combinator
Promise.allSettled
Waits for every promise to settle (fulfill or reject) and always resolves with an array of result descriptors. Each entry is either { status: 'fulfilled', value } or { status: 'rejected', reason }.
Promise.allSettled(iterable) Parameters
| Parameter | Purpose |
|---|---|
| iterable | Iterable of promises or values |
| never rejects | The returned promise itself always fulfills — you inspect statuses |
| result shape | {status: 'fulfilled', value} | {status: 'rejected', reason} |
Examples
const results = await Promise.allSettled(urls.map(u => fetch(u)));
const ok = results.filter(r => r.status === 'fulfilled').map(r => r.value);
const failed = results.filter(r => r.status === 'rejected').map(r => r.reason); Runs all requests to completion and partitions successes from failures.
await Promise.allSettled([
Promise.resolve('ok'),
Promise.reject(new Error('boom'))
]);
// [{status:'fulfilled', value:'ok'}, {status:'rejected', reason:Error}] One rejection does not abort the others.
const settled = await Promise.allSettled([]);
console.log(settled); // [] Empty iterable resolves with an empty array.
Gotcha
The outer promise never rejects — forgetting to check r.status silently ignores errors. ES2020+ only; polyfill for older runtimes.
Related
Promise.all
Waits for all promises in an iterable to fulfill and resolves with an array of their values in original order. Rejects immediately with the reason of the first promise that rejects (fail-fast).
Promise.any
Resolves with the value of the first promise to fulfill, ignoring any rejections until a success occurs. If every promise rejects, it rejects with an AggregateError whose .errors array contains each reason.
Promise.race
Settles as soon as the first promise in the iterable settles, adopting its state (fulfilled or rejected). The remaining promises keep running but their outcomes are ignored.
← All JS Promise reference · async/await vs promises vs callbacks