Skip to main content

waitWithTimeout

Callable

  • waitWithTimeout<T>(awaitable: Promise<T> | AsyncFunction<T, unknown>, timeout: number, error: Error): Promise<T>
  • waitWithTimeout<T>(awaitable: Promise<T> | AsyncFunction<T, unknown>, timeout: number): Promise<T | undefined>

  • Wait for a promise but interrupt it if it did not resolve within a given timeout. If the timeout reached, before the promise code resolve, either throw an error if an error object was provided, or return undefined.


    Type parameters

    • T

    Parameters

    • awaitable: Promise<T> | AsyncFunction<T, unknown>

      The promise or function to wait for.

    • timeout: number

      The timeout in milliseconds.

    • error: Error

      (Optional) The error to throw if the timeout reached.

    Returns Promise<T>