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.
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:
In each rejected result, there are two properties: