Function timeout

  • Waits for given number of milliseconds before timing out. If provided code block does not complete within the given time, the promise will be rejected with new Error('TIMEOUT') error.

    const result = await timeout(1000, async () => {
    return 123;
    });

    Type Parameters

    • T

    Parameters

    • ms: number

      Number of milliseconds to wait before timing out.

    • code: Code<T> | Promise<T>

      Code block or promise to execute.

    Returns Promise<T>

    The result of the code block or promise.