timeout.d.ts 592 B

1234567891011121314151617
  1. import type { Code } from './types';
  2. /**
  3. * Waits for given number of milliseconds before timing out. If provided code
  4. * block does not complete within the given time, the promise will be rejected
  5. * with `new Error('TIMEOUT')` error.
  6. *
  7. * ```ts
  8. * const result = await timeout(1000, async () => {
  9. * return 123;
  10. * });
  11. * ```
  12. *
  13. * @param ms Number of milliseconds to wait before timing out.
  14. * @param code Code block or promise to execute.
  15. * @returns The result of the code block or promise.
  16. */
  17. export declare const timeout: <T>(ms: number, code: Code<T> | Promise<T>) => Promise<T>;