Glossary / Promise.allSettled
Promise.allSettled
Promise.allSettled(iterable) waits until every input Promise settles, then fulfills with an array describing each outcome. It is useful when independent operations should all be allowed to finish and the caller needs both successes and failures—for example, a dashboard that loads several optional panels.
Result contract
const results = await Promise.allSettled(tasks);
for (const result of results) {
if (result.status === "fulfilled") use(result.value);
else report(result.reason);
}
Each result is either { status: "fulfilled", value } or { status: "rejected", reason }, in the original input order. Non-Promise values are treated as fulfilled. An empty iterable fulfills with an empty array. It does not reject merely because an input rejects, and it does not cancel operations. The caller must decide how many failures are acceptable and what constitutes a partial-success outcome.
Because it waits for all inputs, a never-settling Promise prevents the aggregate from settling. Add individual timeouts/cancellation where the product requires bounded waiting. As with Promise.all, avoid unbounded fan-out and preserve context for each task result.
Interview questions
- When use allSettled instead of all? When every result matters even if some operations fail.
- Does allSettled reject for rejected inputs? No; it fulfills with per-input status records.
- What order are results in? Input order.
- Does it cancel or timeout pending operations? No.