Promise.allSettled()

Waits for all promises to settle and reports each outcome.

Since ES2020 Spec ↗

Syntax

Promise.allSettled(iterable)

Returns

Promise — A promise fulfilling with an array of `{ status, value }` or `{ status, reason }` objects.

Examples

Promise.allSettled([
  Promise.resolve(1),
  Promise.reject("err"),
]).then(r => console.log(JSON.stringify(r)));
Output
[{"status":"fulfilled","value":1},{"status":"rejected","reason":"err"}]
Promise.allSettled([Promise.resolve("ok")])
  .then(r => console.log(r[0].status));
Output
fulfilled

Notes

- Never rejects; it always fulfills once every input has settled. - Each result has `status` of `"fulfilled"` (with `value`) or `"rejected"` (with `reason`). - Best when you want every result even if some fail.

Browser & runtime support

EnvironmentSince version
chrome 76
firefox 71
safari 13
edge 79
node 12.9

See also