Promise.allSettled
Waits for every promise to settle and reports each result — success or failure.
Available since: ES2020
Syntax
Promise.allSettled(promises)Parameters
| Parameter | Type | Description |
|---|---|---|
| promises | Iterable | An array of promises. |
Return value
PromiseA promise of an array of objects with status and value (or reason).
Examples
Results together with errors:
const results = await Promise.allSettled([
Promise.resolve('ok'),
Promise.reject(new Error('Failed')),
]);
for (const result of results) {
console.log(result.status, result.value ?? result.reason.message);
}Output:
fulfilled ok
rejected FailedOnly successful values:
const results = await Promise.allSettled([Promise.resolve(1), Promise.reject(new Error('x')), Promise.resolve(3)]);
const values = results.filter((r) => r.status === 'fulfilled').map((r) => r.value);
console.log(values.join(', '));Output:
1, 3Notes
It never rejects: each error just ends up in its own object with the rejected status.
See also
- Promise.all — Waits for all promises in parallel.
- Promise.any — Returns the first successful result and skips errors.
Related recipes
In the tutorial
- Several promises at once — Promise.all, Promise.allSettled, Promise.race and Promise.any in JavaScript: how to wait for several asynchronous actions at the same time.