Library API
    Preparing search index...

    Function sleep

    • Introduces a wait-timer that will reject with an Error on timeout. Best used with Promise.race([myTask(), sleep()]).

      Parameters

      • msg: string = 'sleep: timed out'

        The string to display on a timeout (default: 'sleep: timed out')

      • timeout: number = 2000

        The number of milliseconds to sleep (default: 2000)

      Returns Promise<Error>

      A Promise that rejects after the specified timeout

      await Promise.race([fetchData(), sleep('Fetch timeout', 5000)]);