Promise.race
Promise.race is a JavaScript static method that returns a promise settled with the outcome of the first input promise or thenable to settle.
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
A Promise class method that settles as soon as the first input promise settles and adopts that promise's outcome.
- How it is used
- Uses Promise.race to coordinate requests when only the first result is needed.
- How deep it goes
- Defines Promise.race and poses a composition exercise, without a worked implementation.
- Examples
- Uses credit availability and TransUnion and Equifax score endpoints in a combined-request exercise.
- What you can do after
- Build a combined promise with Promise.all and Promise.race to wait for required data and one of several alternatives.
Secrets of the JavaScript Ninja, Third Edition
Promise.race is a static Promise method that creates a promise settled according to the first supplied promise to settle.
- How it is used
- Uses the first-settled result to impose a time limit on another promise.
- How deep it goes
- Defines first-settled behavior and demonstrates a fetch timeout with explicit request cancellation.
- Examples
- Demonstrates racing a delayed fetch against a one-second timer and aborting the request on timeout.
- What you can do after
- Apply Promise.race to enforce a timeout, using AbortController when the losing fetch should be canceled.
Read how Secrets of the JavaScript Ninja, Third Edition explains Promise.race →
Also covered in
What to know first
- exceptionAn exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- promiseA JavaScript Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value or reason.
Related concepts
- promiseuses · A JavaScript Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value or reason.
- Promise.allcontrasts with · Promise.all is a JavaScript static method that returns a promise fulfilled with an array of results when all input promises fulfill, or rejected if any input promise rejects.
- hash functionuses · A hash function is a deterministic function that maps input data to a hash value, typically of fixed size, for uses such as lookup, indexing, comparison, or integrity checking.
Questions about Promise.race
What is Promise.race?
Promise.race is a JavaScript static method that returns a promise settled with the outcome of the first input promise or thenable to settle.
Which Manning books explain Promise.race?
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond and Secrets of the JavaScript Ninja, Third Edition.
What should I know before learning Promise.race?
Manning books that teach Promise.race usually introduce exception and promise first.
What is the difference between Promise.race and Promise.all?
Promise.race is a JavaScript static method that returns a promise settled with the outcome of the first input promise or thenable to settle. Promise.all is a JavaScript static method that returns a promise fulfilled with an array of results when all input promises fulfill, or rejected if any input promise rejects.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

