A Promise class method that settles as soon as the first input promise settles and adopts that promise's outcome.
Promise.race takes an array of promises and returns a new promise that waits for the first one to resolve. section 30.4
Wait for one of two credit scores
A page needs a user’s credit availability and at least one credit score. Combine Promise.all with Promise.race so the page can wait for the availability request and whichever score request finishes first. section 30.4
How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it
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.
How it connects
Connects Promise.race with promises and Promise.all.
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 deterministically maps input data to a value in a bounded output range, commonly for indexing, lookup, comparison, or integrity checking.
This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.