JavaScript Promise.race() Method
The Promise.race() static method settles as soon as the first of several promises settles, whether it succeeds or fails. It's often used to add a timeout.
Description
The Promise.race() static method returns a promise that settles with the first input promise to settle, either fulfilling or rejecting. A common use is a timeout: race the real task against a promise that rejects after a delay.
If the iterable is empty, the returned promise stays pending forever. The "losing" promises aren't cancelled; they keep running and their results are simply ignored, so a timed-out fetch() still downloads in the background unless you abort it with an AbortController.
For timeouts on requests, AbortSignal.timeout(ms) passed as the signal option to fetch() is now a simpler alternative that also stops the request itself.
Syntax
Promise.race(iterable)Parameters
- iterableAn iterable of promises or values.
Return Value
A promise that settles in the same way as the first input promise to settle.
Example
Browser Support
The following information will show you the current browser support for the Promise.race() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





