Function timeout

  • Returns a promise that rejects with a TimeoutError after a specified delay.

    Parameters

    • ms: number

      The delay duration in milliseconds.

    Returns Promise<never>

    A promise that rejects with a TimeoutError after the specified delay.

    Throws a TimeoutError after the specified delay.

    try {
    await timeout(1000); // Timeout exception after 1 second
    } catch (error) {
    console.error(error); // Will log 'The operation was timed out'
    }