What is Promise.allSettled in JavaScript?

The Promise.allSettled method takes a list of promises as an input and returns a single promise. The returned promise will resolve after all the passed promises are either fulfilled or rejected.

Code

Console

In the above code, we have two promises: promise1 is already resolved and promise2 will be rejected after 100 milliseconds. Upon calling Promise.allSettled with these two promises, we will get a pending promise. Upon resolving it, we will get an array of promise results.

In each fulfilled result, there are two properties:

  • status with value fulfilled
  • valuethe resolved value of the promise

In each rejected result, there are two properties:

  • status with value rejected
  • errorthe error message

Free Resources