Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Wait for the Fastest JavaScript Promise to Settle with Promise.race()

    javascriptJavaScript

    The Promise.race() method accepts an array (or any other iterable) of promises as a parameter. It returns a Promise object that is fulfilled or rejected once the first input promise is fulfilled or rejected:

    • As soon as any input promise is fulfilled, the returned Promise object is fulfilled with that value.
    • As soon as any input promise is rejected, the returned Promise object is rejected with that reason.

    Promise.race() can be used to race multiple promises against each other and find the first promise to settle.