PromiseallSettled
Promise.allSettled is a Promise utility that accepts an iterable of promises (and/or values) and returns a single promise that resolves after all input promises have settled, either fulfilled or rejected. When fulfilled, the returned value is an array describing the outcome of each input in the same order as provided. Each element is an object of the form { status: 'fulfilled', value: ... } or { status: 'rejected', reason: ... }.
Unlike Promise.all, which rejects as soon as one input rejects, allSettled waits for every input to settle.
Common use cases include performing multiple asynchronous operations in parallel and collecting all results, including failures,
Promise.allSettled([Promise.resolve(1), Promise.reject(new Error('oops')), 3]).then(results => console.log(results));
[
{ status: 'fulfilled', value: 1 },
{ status: 'rejected', reason: Error('oops') },
{ status: 'fulfilled', value: 3 }
]