Reference / JavaScript
Promise.allSettled()
Returns a single Promise that fulfills after all of the given promises have either fulfilled or rejected.
Syntax
Promise.allSettled(iterable: Iterable<Promise<T> | T>): Promise<PromiseSettledResult<T>[]>Parameters
| Name | Type | Description |
|---|---|---|
| iterable | Iterable | An iterable containing promises. |
Examples
Handling mixed outcomes
const promises = [Promise.resolve('OK'), Promise.reject(new Error('Fail'))];
const results = await Promise.allSettled(promises);
results.forEach(r => console.log(r.status));Unlike Promise.all(), it will never short-circuit when a single promise rejects.