Skip to content
jshacks.dev
Async

Promise.all vs Promise.allSettled and When to Use Each

Promise.all rejects on the first failure and Promise.allSettled waits for every result. See outputs side by side, the failure behavior and a rule for choosing.

7 min read
Summarize in AI
Flat illustration of two options weighed side by side, with the JavaScript, npm, TypeScript and Node.js logos.

Both methods take an array of promises and return one promise, and they behave identically when everything succeeds. The difference shows up the first time one call fails. Promise.all rejects immediately with that one error and throws away every other result, while Promise.allSettled waits for all of them and tells you, for each, what happened. Choosing wrongly gives you either a page that blanks because an optional widget failed, or an import that reports success while half the rows were lost. This post compares Promise.all vs Promise.allSettled in Node.js 24 with the same inputs run through both, then gives a rule for deciding.

The same inputs, two results

Here are three simulated calls, where the second fails after 50 milliseconds.

compare.mjsJavaScript
const delay = (ms, value) => new Promise((resolve) => setTimeout(resolve, ms, value));
const fail = (ms, message) =>
  new Promise((_, reject) => setTimeout(reject, ms, new Error(message)));

const makeCalls = () => [delay(100, "profile"), fail(50, "billing down"), delay(150, "orders")];

try {
  const all = await Promise.all(makeCalls());
  console.log("all:", all);
} catch (error) {
  console.log("all rejected:", error.message);
}

const settled = await Promise.allSettled(makeCalls());
console.log(settled);
Text
all rejected: billing down
[
  { status: 'fulfilled', value: 'profile' },
  {
    status: 'rejected',
    reason: Error: billing down
        at Timeout._onTimeout (file:///compare.mjs:3:48)
        at listOnTimeout (node:internal/timers:594:17)
        at process.processTimers (node:internal/timers:529:7)
  },
  { status: 'fulfilled', value: 'orders' }
]

The stack lines in the second block depend on your file path and Node.js build, so yours will differ, but the shape does not change. Promise.all gives you the first error and nothing else. Promise.allSettled returns one object per input, in input order, with a status of "fulfilled" and a value, or "rejected" and a reason. It never rejects because of its inputs, so it needs no try/catch for them.

What happens to the other promises

A point that surprises people: when Promise.all rejects, the other promises are not cancelled. Promises cannot be cancelled. The slower calls keep running to completion, their results are simply ignored. If those calls have side effects, such as writing to a database, the side effects still happen. Cancellation needs an AbortSignal passed into each call, as in implementing a cancelable promise.

keeps-running.mjsJavaScript
const delay = (ms, value) => new Promise((resolve) => setTimeout(resolve, ms, value));

const slow = delay(100, "slow").then((value) => {
  console.log("slow call still finished:", value);
  return value;
});
const failing = new Promise((_, reject) => setTimeout(reject, 20, new Error("early failure")));

try {
  await Promise.all([slow, failing]);
} catch (error) {
  console.log("caught:", error.message);
}
await delay(150);
Text
caught: early failure
slow call still finished: slow

The catch block runs at 20 milliseconds. The slow call finishes at 100 anyway, which is why a failed Promise.all is not a safe point to assume that nothing else is happening.

Handling the settled results

The result array of allSettled is easy to misuse. The usual need is to split successes from failures, which two filter calls do cleanly.

split.mjsJavaScript
const results = await Promise.allSettled([
  Promise.resolve({ id: 1 }),
  Promise.reject(new Error("row 2 invalid")),
  Promise.resolve({ id: 3 }),
]);

const fulfilled = results.filter((r) => r.status === "fulfilled").map((r) => r.value);
const rejected = results.filter((r) => r.status === "rejected").map((r) => r.reason.message);

console.log(fulfilled);
console.log(rejected);
Text
[ { id: 1 }, { id: 3 } ]
[ 'row 2 invalid' ]

If you need to know which input failed, keep the input array beside the results and use the index, since the order is preserved: results[i] belongs to inputs[i]. A second approach is to wrap each call so its result already carries its identity, which survives later reordering or filtering.

A rule for choosing

Ask one question: can the caller do something useful with a partial result?

SituationUseReason
All pieces needed to render or continuePromise.allOne missing piece makes the rest worthless, so fail fast
Optional extras on a pagePromise.allSettledA failed widget should not blank the page
Batch import or notificationsPromise.allSettledYou must report which items failed
Startup checks that must all passPromise.allAny failure should stop the boot
Independent writes where you need a summaryPromise.allSettledCount successes and failures

The first row is the common one. A dashboard that needs the user and their permissions cannot show anything without both, and an early failure lets you show an error sooner than waiting for the slowest call to also fail or succeed. The other rows are where allSettled earns its keep.

Failing late and silently

The danger of allSettled is that nothing throws. Code that awaits it and then uses only the fulfilled values will happily proceed when everything failed.

silent.mjsJavaScript
const results = await Promise.allSettled([
  Promise.reject(new Error("a")),
  Promise.reject(new Error("b")),
]);

const values = results.filter((r) => r.status === "fulfilled").map((r) => r.value);
console.log("processed", values.length, "items");

const failures = results.filter((r) => r.status === "rejected");
if (failures.length === results.length) {
  console.log("every call failed, treat as an error");
}
Text
processed 0 items
every call failed, treat as an error

Without the second check, this job reports "processed 0 items" and exits normally, and the monitoring shows green. Decide the failure policy explicitly, such as "fail if more than 10 percent failed" or "fail if all failed", and write it as code right after the allSettled call.

Two neighbors complete the set. Promise.race settles with the first promise to settle, success or failure, which suits timeouts. Promise.any fulfills with the first success and rejects only when all fail, with an AggregateError that lists every reason in its errors array. The comparison between those two is in Promise.race vs Promise.any. Promise.all and Promise.allSettled are the pair for "wait for everything", and the other two are for "wait for one".

A common middle path

Often you want fail-fast for some calls and tolerance for others in the same function. Combine the two: wrap the optional calls so they cannot reject, then pass everything to Promise.all.

middle.mjsJavaScript
const optional = (promise, fallback) => promise.catch(() => fallback);

const [user, recommendations] = await Promise.all([
  Promise.resolve({ name: "Ada" }),
  optional(Promise.reject(new Error("service down")), []),
]);

console.log(user.name, recommendations.length);
Text
Ada 0

The user call is required, so its failure still rejects the whole thing. The recommendations call is optional, so a failure becomes an empty list. This reads better than unpacking settled results by position, and it records the policy next to the call.

Where the advice stops

Neither method limits concurrency. Both start with an array of promises that already exist, so a thousand-element array means a thousand calls in flight. Use a pool for large lists. Neither one retries, and neither one cancels. And if your array is empty, Promise.all([]) resolves to [] and Promise.allSettled([]) also resolves to [] immediately, which is correct but sometimes unexpected when the array came from a filter that removed everything.

Choosing in real code

Two short examples show how the decision plays out. A checkout page loads the cart, the shipping options and the saved payment methods. If any one is missing, the user cannot pay, so Promise.all is right: the first failure should produce an error screen immediately, not after the slower calls finish. A nightly job that sends 5,000 reminder emails is the opposite. One address failing must not stop the other 4,999, and the operator needs a count of failures at the end, so Promise.allSettled is right, followed by an explicit check that the failure rate is acceptable.

When you are unsure, ask what the caller does on partial success. If the honest answer is "show an error anyway", use Promise.all. If it is "show what we have and a note about the rest", use Promise.allSettled. The mistake to avoid is choosing allSettled to dodge writing error handling. It does not remove the handling, it moves it to the code after the await, where it is easy to forget.

Types and tooling

In TypeScript the two return different shapes, and the compiler helps. Promise.all on a tuple of promises returns a tuple of their value types, so destructuring keeps each type. Promise.allSettled returns an array of PromiseSettledResult<T>, a union that you narrow by checking status. A filter with a type guard gives you a clean T[] of fulfilled values. Linters such as @typescript-eslint/no-floating-promises also catch the mistake of calling either method without awaiting the result, which silently drops errors.

Logging deserves one habit: when you use allSettled, log every rejection reason with enough context to find the input, for example the id or URL. A bare "3 of 20 failed" line tells the next engineer nothing, while the list of failing ids tells them where to look.

Share

Keep reading

Flat illustration of an editor window full of code, with the Google Chrome, JavaScript and npm logos.
Browser

script Tags: async, defer and type=module

Compare classic, async, defer and module script tags: when each downloads, when each runs, how order is kept and which one to pick for each kind of script.

6 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.