Introduces a wait-timer that will reject with an Error on timeout. Best used with Promise.race([myTask(), sleep()]).
Promise.race([myTask(), sleep()])
The string to display on a timeout (default: 'sleep: timed out')
The number of milliseconds to sleep (default: 2000)
A Promise that rejects after the specified timeout
await Promise.race([fetchData(), sleep('Fetch timeout', 5000)]); Copy
await Promise.race([fetchData(), sleep('Fetch timeout', 5000)]);
Introduces a wait-timer that will reject with an Error on timeout. Best used with
Promise.race([myTask(), sleep()]).