What is Promise.allSettled()?

Promise.allSettled(iterable) waits for every promise to finish, whether it succeeds or fails, and fulfills with an array of result objects describing each outcome; it never rejects.

Result shape

Each item is either:

  • { status: "fulfilled", value }
  • { status: "rejected", reason }

Results are in the same order as the input.

When to use it

When operations are independent and partial success is acceptable:

  • Loading several dashboard widgets: show the ones that worked and an error card for the rest.
  • Sending notifications to many recipients and reporting which failed.
  • Cleanup tasks where every one should be attempted.
  • Batch uploads with a per-file status.

allSettled vs all

  • Promise.all is all-or-nothing and rejects on the first failure, losing the other results.
  • Promise.allSettled always gives you every outcome.

Handling the results

Split them with filter on status, or use Object.groupBy(results, r => r.status). Remember that allSettled itself never rejects, so a try/catch around it will not catch the individual failures. You must inspect each result.

Retrying failures

A common pattern is to run allSettled, collect the rejected items, and retry just those.

Code example

js
1const loadWidget = (name, ms, fail = false) =>
2 new Promise((resolve, reject) =>
3 setTimeout(() => (fail ? reject(new Error(`${name} unavailable`)) : resolve({ name, data: `${name} data` })), ms)
4 );
5
6const results = await Promise.allSettled([
7 loadWidget("sales", 20),
8 loadWidget("weather", 10, true),
9 loadWidget("news", 15),
10]);
11
12console.log(results.map((r) => r.status)); // ["fulfilled", "rejected", "fulfilled"]
13
14for (const [i, r] of results.entries()) {
15 if (r.status === "fulfilled") console.log(`widget ${i}: show`, r.value.name);
16 else console.log(`widget ${i}: error card ->`, r.reason.message);
17}
18
19// Group outcomes
20const { fulfilled = [], rejected = [] } = Object.groupBy(results, (r) => r.status);
21console.log(`${fulfilled.length} loaded, ${rejected.length} failed`); // 2 loaded, 1 failed
22
23// Compare: Promise.all loses everything on one failure
24try {
25 await Promise.all([loadWidget("sales", 20), loadWidget("weather", 10, true)]);
26} catch (e) {
27 console.log("Promise.all rejected:", e.message); // Promise.all rejected: weather unavailable
28}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the JavaScript set.

Open in study app