What is the difference between Promise.all and Promise.allSettled?

EasyPhone Screen
AppleFrontend Developer
156

Explain the difference between Promise.all() and Promise.allSettled() in JavaScript. When would you use each?

1 Answer

134
Top Answer

Promise.all

Rejects immediately if ANY promise rejects.

Promise.all([
  Promise.resolve(1),
  Promise.reject('error'),
  Promise.resolve(3)
])
.then(results => console.log(results))
.catch(err => console.log(err)); // 'error'

Promise.allSettled

Waits for ALL promises, never rejects.

Promise.allSettled([
  Promise.resolve(1),
  Promise.reject('error'),
  Promise.resolve(3)
])
.then(results => console.log(results));
// [
//   { status: 'fulfilled', value: 1 },
//   { status: 'rejected', reason: 'error' },
//   { status: 'fulfilled', value: 3 }
// ]

When to Use Each:

Promise.all: When you need ALL promises to succeed (fail-fast)

  • Fetching data that all depends on each other
  • Validation where any failure should stop

Promise.allSettled: When you want results regardless of failures

  • Batch operations where some can fail
  • Collecting results from multiple sources
PromiseMaster

Share Your Answer

Help others by sharing your knowledge and experience with this question.

Coming soon...

Related Questions

View all

More from Apple

View all