liveBook · Manning

Promise.race

As explained in 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.

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.

Related concepts

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.