Summary: Working with Multiple Promises

Get a brief summary of working with multiple promises.

We'll cover the following

Handling multiple promises

For times when we want to monitor and respond to multiple promises at the same time, JavaScript provides several methods. Each method behaves slightly differently, but they all allow us to run promises in parallel and respond to them as a group:

  • Promise.all(): The returned promise is fulfilled when all of the promises are fulfilled, and the returned promise is rejected when any promise is rejected.
  • Promise.allSettled(): The returned promise is always fulfilled with an array of results from the promise, and the returned promise is never rejected.
  • Promise.any(): The returned promise is fulfilled when the first promise is fulfilled, and the returned promise is rejected when all of the promises are rejected.
  • Promise.race(): The returned promise is fulfilled when the first promise to settle is fulfilled, and the returned promise is rejected when the first promise to settle is rejected.

Each of these methods is appropriate for different use cases, and it’s up to you to decide which is appropriate in any given situation.

Get hands-on with 1200+ tech skills courses.