main.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Some predefined delay values (in milliseconds).
  3. */
  4. export enum Delays {
  5. Short = 500,
  6. Medium = 2000,
  7. Long = 5000,
  8. }
  9. /**
  10. * Returns a Promise<string> that resolves after a given time.
  11. *
  12. * @param {string} name - A name.
  13. * @param {number=} [delay=Delays.Medium] - A number of milliseconds to delay resolution of the Promise.
  14. * @returns {Promise<string>}
  15. */
  16. function delayedHello(
  17. name: string,
  18. delay: number = Delays.Medium,
  19. ): Promise<string> {
  20. return new Promise((resolve: (value?: string) => void) =>
  21. setTimeout(() => resolve(`Hello, ${name}`), delay),
  22. )
  23. }
  24. // Please see the comment in the .eslintrc.json file about the suppressed rule!
  25. // Below is an example of how to use ESLint errors suppression. You can read more
  26. // at https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules
  27. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  28. export async function greeter(name: any) {
  29. // eslint-disable-line @typescript-eslint/no-explicit-any
  30. // The name parameter should be of type string. Any is used only to trigger the rule.
  31. return await delayedHello(name, Delays.Medium)
  32. }
  33. await greeter('world').then(console.log)