Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Promises and Async

Promise.allSettled()

Reference for Promise.allSettled(): wait for every promise to finish, read each status, value and reason, and report successes and failures together.

Promise.allSettled() waits until every input promise has settled, whether it fulfilled or rejected, and then fulfills with an array that describes each outcome. Unlike Promise.all(), one failure never hides the other results, and the returned promise itself never rejects because of an input.

It is the right choice for "try everything and report" jobs: uploading several files, pinging several services, running independent checks.

JavaScript
const outcomes = await Promise.allSettled([taskA(), taskB()]);

Try it

JS Reading each outcome

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Summarizing successes and failures

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Promise.allSettled(iterable)
Name Description
iterable An iterable of promises or plain values.

Return value: a promise that fulfills with an array, in input order, of result objects:

Shape When
{ status: "fulfilled", value } The input fulfilled with value.
{ status: "rejected", reason } The input rejected with reason.

An empty iterable gives an empty array.

Exceptions: if the argument is not iterable, the returned promise rejects with a TypeError.

Usage notes

  • Never rejects for input failures. You do not need a catch() to deal with individual task errors, only to deal with bad arguments or errors in your own code.
  • Order is the input order, not the finishing order.
  • Check status first. Only a fulfilled result has value, only a rejected one has reason.
  • Waits for the slowest. The total time is that of the last task to finish. If you want to stop early, combine it with a timeout or an AbortController.
  • Compare: Promise.all() fails fast; Promise.any() wants one success; Promise.race() takes the first outcome of any kind.
  • Rejection reasons are often Error objects; log reason rather than the whole result object when you want readable output.

Browser support

Supported in all current browsers and Node.js; it is newer than Promise.all(), so very old environments may lack it.