Promise.allSettled: Wait for Everything
Learn how Promise.allSettled waits for every promise to finish, what its result objects look like and when it is better than Promise.all for partial failure.

Promise.all gives up at the first failure. Promise.allSettled does not give up at all: it waits until every promise has either fulfilled or rejected, then hands you one report that says what happened to each. It never rejects, which changes how you write the code around it, because the failure information moves from a catch block into the data. This post covers the shape of the result on Node.js 24 with printed output, the three patterns where it is the right tool (batch jobs, independent widgets, cleanup), how to split successes from failures and the mistake of assuming that no rejection means no error. It was added in ES2020, so every supported runtime has it.
The result shape
Each entry is an object with a status. A fulfilled entry has value, and a rejected one has reason.
const results = await Promise.allSettled([
Promise.resolve("a"),
Promise.reject(new Error("b failed")),
42,
]);
console.log(results);[
{ status: 'fulfilled', value: 'a' },
{
status: 'rejected',
reason: Error: b failed
at ...
},
{ status: 'fulfilled', value: 42 }
]The stack lines depend on the file path, so they are elided. The order matches the input, as with Promise.all, and plain values count as fulfilled. The combined promise itself fulfills here even though one input rejected. That is the point, and also the source of the common bug covered below.
Compared with Promise.all
Promise.all | Promise.allSettled | |
|---|---|---|
| Rejects when an input rejects | Yes, immediately | Never |
| Waits for every input | Only if none reject | Always |
| Result | Array of values | Array of status objects |
| Best for | All-or-nothing work | Independent work where partial results matter |
The decision is a policy question. If one failure makes the others worthless, you want fail-fast. If each result stands alone, you want everything.
const delay = (ms, value) =>
new Promise((resolve) => setTimeout(() => resolve(value), ms));
const failAfter = (ms, message) =>
new Promise((_, reject) => setTimeout(() => reject(new Error(message)), ms));
const started = Date.now();
const settled = await Promise.allSettled([
failAfter(10, "early failure"),
delay(40, "late success"),
]);
console.log("waited for the slow one:", Date.now() - started >= 35);
console.log(settled.map((r) => r.status));waited for the slow one: true
[ 'rejected', 'fulfilled' ]Promise.all would have rejected after about 10 ms and never reported the late success. Here the report arrives after about 40 ms, once the last promise finishes.
Splitting successes and failures
Because the result is a plain array, you can filter it.
const settled = await Promise.allSettled([
Promise.resolve(1),
Promise.reject(new Error("two failed")),
Promise.resolve(3),
Promise.reject(new Error("four failed")),
]);
const values = settled
.filter((result) => result.status === "fulfilled")
.map((result) => result.value);
const errors = settled
.filter((result) => result.status === "rejected")
.map((result) => result.reason.message);
console.log(values);
console.log(errors);[ 1, 3 ]
[ 'two failed', 'four failed' ]Filtering by status also narrows the type in TypeScript, so result.value is only accessible on the fulfilled branch.
const results = await Promise.allSettled([fetchUser(), fetchPosts()]);
for (const result of results) {
if (result.status === "fulfilled") {
console.log(result.value);
} else {
console.log(result.reason);
}
}Pattern 1: batch jobs
Importing a list of records, sending notifications, warming caches. You want to try everything and report the failures, not stop at the first.
async function sendEmail(address) {
if (!address.includes("@")) throw new Error(`bad address: ${address}`);
return `sent to ${address}`;
}
const addresses = ["[email protected]", "not-an-address", "[email protected]"];
const results = await Promise.allSettled(addresses.map(sendEmail));
const failed = results
.map((result, index) => ({ result, address: addresses[index] }))
.filter(({ result }) => result.status === "rejected");
console.log("sent:", results.length - failed.length);
console.log("failed:", failed.map(({ address }) => address));sent: 2
failed: [ 'not-an-address' ]Keeping the index lets you map a failure back to its input, which the result objects do not carry by themselves. For large lists, combine it with batching, since allSettled starts everything at once like all.
Pattern 2: independent parts of a page
A dashboard with four widgets should render three if the fourth service is down.
const widgets = {
weather: () => Promise.resolve("sunny"),
stocks: () => Promise.reject(new Error("stocks api down")),
news: () => Promise.resolve("3 headlines"),
};
const names = Object.keys(widgets);
const results = await Promise.allSettled(names.map((name) => widgets[name]()));
results.forEach((result, index) => {
const name = names[index];
console.log(
name,
result.status === "fulfilled" ? result.value : `unavailable (${result.reason.message})`,
);
});weather sunny
stocks unavailable (stocks api down)
news 3 headlinesPattern 3: cleanup that must all run
When shutting down, every cleanup should be attempted even if one fails.
const cleanups = [
async () => console.log("closed database"),
async () => {
throw new Error("cache close failed");
},
async () => console.log("closed queue"),
];
const results = await Promise.allSettled(cleanups.map((fn) => fn()));
const errors = results.filter((r) => r.status === "rejected");
console.log("cleanup errors:", errors.length);closed database
closed queue
cleanup errors: 1With Promise.all, the thrown error would reject the whole thing, and while the other cleanups still ran, you would not have waited for them to complete before exiting.
The mistake: no rejection is not no failure
Since allSettled never rejects, wrapping it in try/catch and trusting that nothing was thrown is a bug. Failures are in the array. Code that ignores the array silently swallows every error.
try {
await Promise.allSettled([Promise.reject(new Error("lost"))]);
console.log("no error thrown, and nothing was checked");
} catch {
console.log("never reached");
}no error thrown, and nothing was checkedIf any failure should surface, check for it and throw yourself. A common helper does exactly that.
async function allOrReport(promises) {
const results = await Promise.allSettled(promises);
const failures = results.filter((r) => r.status === "rejected");
if (failures.length > 0) {
throw new AggregateError(
failures.map((f) => f.reason),
`${failures.length} of ${results.length} failed`,
);
}
return results.map((r) => r.value);
}
try {
await allOrReport([Promise.resolve(1), Promise.reject(new Error("x"))]);
} catch (error) {
console.log(error.message, error.errors.length);
}1 of 2 failed 1This waits for everything, which Promise.all does not, and still fails loudly. AggregateError is the standard container for several errors.
When not to use it
Skip allSettled when a single failure makes the rest meaningless, such as loading the pieces of one record that cannot render partially. You gain nothing by waiting for the others, and Promise.all frees you sooner. Also skip it when you need only the first result: Promise.any and Promise.race cover that.
Reporting failures to the people who need to know
The point of waiting for everything is usually to say something afterwards, and how you say it matters. A batch job that quietly drops failures is worse than one that stops, because nobody learns that records were lost. After an allSettled call, decide what the failures mean for your caller. For an interactive page, it may mean showing a notice next to the one widget that failed while the rest render. For a nightly import, it may mean writing the failed inputs to a log file or a retry queue, and exiting with a non-zero code so the scheduler marks the run as partly failed.
It also helps to keep failures structured. A bare reason object is hard to group, while a small record with the input, the error code and a short message can be counted, searched and retried. When the same error repeats across many inputs, summarize it by its code, since a thousand identical lines hide the one different failure you needed to see.
A second consideration is memory and load. Because allSettled starts every operation at once, a large list can exhaust connections or trip a rate limit, and since nothing is rejected early, you find out only at the end. Process large lists in batches, collect each batch's results and then move on. The batch size is a knob you can tune against the service you call, and a small constant such as five or ten is a safe starting point.
Finally, be careful about retries. A failed result tells you what failed, and it is tempting to loop until everything succeeds. Bound the loop, wait between attempts and give up on errors that cannot improve, such as a validation failure, so a bad record does not retry forever.
Testing code that uses Promise.allSettled
A function that reports partial results needs tests for the partial cases, and a test with all successes and one with all failures are not enough. Write a test with a mix, and assert both halves of the output: the values that came through and the errors that were collected, along with their association to the inputs that produced them. Add a test where the slowest input is the one that fails, to confirm that the function really waits for everything. Check that a failure does not throw, if that is the contract, and that the caller can still tell, from the return value, that something went wrong. If your code turns failures into a thrown aggregate error after collecting them, assert on the errors array of the AggregateError and on the summary message. Using promises that you resolve and reject by hand makes each of these cases deterministic.


