Skip to main content

Promise.allSettled() in JavaScript

Promise.allSettled() is a static method that takes an array (or any other iterable) of promises and returns a new promise which fulfills once every passed promise has settled. It does not matter whether they succeeded (fulfilled) or failed (rejected): the method waits for all results, not only the successful ones.

Theory

TL;DR

  • Promise.allSettled(iterable) waits until all promises settle in any way.
  • The returned promise always becomes fulfilled, it never rejects.
  • Its value is an array of {status, value} or {status, reason} objects in input order.
  • Promise.all(), by contrast, rejects on the very first reject and loses the remaining results.
  • Typical use: bulk data loading, parallel validation, batched request sending.

Quick example

javascript
const p1 = Promise.resolve('Success'); const p2 = Promise.reject('Error'); const p3 = Promise.resolve('One more'); Promise.allSettled([p1, p2, p3]) .then(results => console.log(results));

Output:

javascript
[ { status: "fulfilled", value: "Success" }, { status: "rejected", reason: "Error" }, { status: "fulfilled", value: "One more" } ]

Every promise settled, the method did not "fall over", it returned a full summary: who succeeded and who failed.

Syntax:

javascript
Promise.allSettled(iterable)

It returns a new promise that always ends up fulfilled and yields an array of objects with the results.

Shape of the result

Every element of the array is an object with the same set of fields:

FieldWhen it appearsValue
statusalways"fulfilled" or "rejected"
valueif fulfilledthe promise result
reasonif rejectedthe failure reason

The element order matches the order of the input promises, so a result is easy to map back onto the original list by index.

When to use Promise.allSettled()

  • When it matters that you wait for all operations to finish, even if some of them fail.
  • When you need to collect all results and errors together, in one report.
  • For example, during bulk data loading, parallel validation, batched request sending, data cleanup and so on.

How it differs from Promise.all()

CharacteristicPromise.all()Promise.allSettled()
When it settlesOnly if all promises succeedWhen all promises settle (with any outcome)
What it returnsAn array of value resultsAn array of {status, value/reason} objects
Behaviour on failureFalls over on the first rejectDoes not fall over, waits for everyone
State of the returned promiseCan be fulfilled or rejectedAlways fulfilled
What it is used forWhen everything has to succeedWhen you need a report on all results

A side by side example:

javascript
const a = Promise.resolve('A'); const b = Promise.reject('Error'); const c = Promise.resolve('C'); // Promise.all Promise.all([a, b, c]) .then(console.log) .catch(err => console.error('Promise.all:', err)); // Promise.allSettled Promise.allSettled([a, b, c]) .then(console.log);

Output:

javascript
Promise.all: Error [ { status: 'fulfilled', value: 'A' }, { status: 'rejected', reason: 'Error' }, { status: 'fulfilled', value: 'C' } ]

Promise.all() stopped at the error, while Promise.allSettled() waited for everyone and returned the full report.

A practical example

Imagine you need to load data from several sources, and even if one of them is unavailable, you still need the rest:

javascript
const urls = ['/user', '/posts', '/comments']; const requests = urls.map(url => fetch(url)); Promise.allSettled(requests) .then(results => { results.forEach((res, i) => { if (res.status === 'fulfilled') { console.log(`${urls[i]}: OK`); } else { console.warn(`${urls[i]}: failed`); } }); });

This way you get a summary across all requests, even if one of them "fell over".

A simple analogy:

Imagine you ordered three deliveries:

  • Promise.all(): if even one delivery does not arrive, you get upset right away and stop waiting for the others.
  • Promise.allSettled(): you wait for every courier, even if one shows up without a parcel, so that you know what happened to each delivery.

Summary table:

MethodBehaviour on failureReturn valueWhen it settles
Promise.all()Falls over on the first rejectAn array of successful valuesWhen all succeed
Promise.allSettled()Never falls overAn array of {status, value/reason}When all are settled

Common mistakes

  • Attaching .catch() and expecting it to fire. The promise from allSettled() does not reject, so failures must be looked up in the array elements whose status === 'rejected', otherwise a breakage goes unnoticed.
  • Mixing up value and reason. A rejected element has no value, a fulfilled one has no reason: check status first.
  • Thinking allSettled() makes code resilient by itself. It only collects a report, the retry or degradation logic is still yours to write.
  • Forgetting about HTTP errors in fetch. fetch rejects only on a network failure, so a 500 response lands in fulfilled and res.ok has to be checked separately.
  • Reaching for allSettled() where fail-fast is wanted. If the first failure makes the rest of the work pointless, Promise.all() finishes sooner and saves resources.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.