Promise.allSettled()
The method for when partial success is a real outcome. Because it never rejects, the try/catch around it is dead code — the failures arrive as data instead.
Demo
Each input is [outcome, value, delay in ms]: 'ok' fulfils with the value, anything else rejects with an Error carrying it. Every input produces a status object, in input order, and the combined promise never rejects — even the second case, where everything failed, resolves normally with two 'rejected' entries. That is why a try/catch around allSettled is dead code: failures arrive as data. Note the values are nested under value and reason, not returned bare as Promise.all would.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| iterable | iterable | yes | Any iterable of promises or plain values. Non-promises are reported as fulfilled. |
Return value
Promise<Array> — A Promise for an array of objects — {status: "fulfilled", value} or {status: "rejected", reason} — in input order. It never rejects.
Common patterns
const rs = await Promise.allSettled(tasks); const ok = rs.filter(r => r.status === "fulfilled").map(r => r.value);
const errors = rs.filter(r => r.status === "rejected").map(r => r.reason);
const all = await Promise.all(tasks);
Examples
Pitfalls
const [a] = await Promise.allSettled([Promise.resolve(1)]); a
const [a] = await Promise.allSettled([Promise.resolve(1)]); a.value
try { await Promise.allSettled(t); } catch { /* unreachable */ }
const bad = rs.filter(r => r.status === "rejected"); if (bad.length) report(bad);
await Promise.allSettled([hangsForever, quick])
tasks.map(t => Promise.race([t, timeout(5000)]))
Promise.allSettled(tasks)
Promise.all(tasks.map(p => p.then(value => ({status: "fulfilled", value}), reason => ({status: "rejected", reason}))))
When to use
- Several independent tasks where partial success is useful
- Dashboards and batch jobs — report what failed, render what worked
- Cleanup and teardown, where every step should be attempted
- Collecting all validation errors rather than the first
- Any failure should abort → Promise.all
- You want the first success → Promise.any
- You want the first result at all → Promise.race
- A task may hang → bound each one with a timeout
Notes
FAQ
all when every task must succeed for the outcome to mean anything — a transaction, a multi-step save. allSettled when the tasks are independent and knowing which ones failed is more useful than aborting.