• Creates a Promise that rejects after ms milliseconds if the provided Promise did not resolve or reject in time.

    Example

    Reject if promise takes over 500ms to resolve or reject

    const timeoutAfter500ms = timeoutPromise(500, "err");
    try {
    await timeoutAfter500ms(myPromise); // takes over 500 ms
    } catch(err) {
    console.log(err); // "err"
    }

    Returns

    a new Promise that either uses the response of the provided Promise or rejects after ms milliseconds

    Parameters

    • ms: number

      the number of milliseconds for the timeout

    • Optional error: unknown

      the optional error to reject with

    Returns (<T>(promise: Promise<T>) => Promise<T>)

Generated using TypeDoc