Promise.any()
Fulfills with the first promise to fulfill, rejecting only if all reject.
Syntax
Promise.any(iterable)
Returns
Promise — A promise that fulfills with the first fulfillment, or rejects with
an `AggregateError` if all reject.
Examples
Promise.any([
Promise.reject("a"),
Promise.resolve("b"),
]).then(v => console.log(v));
Output
b
Promise.any([
Promise.reject("x"),
Promise.reject("y"),
]).catch(e => console.log(e.name));
Output
AggregateError
Notes
- Ignores rejections as long as at least one promise fulfills.
- If every promise rejects, it rejects with an `AggregateError` whose
`errors` array holds the rejection reasons.
- Contrast with `Promise.race()`, which settles on the first to settle
(fulfilled or rejected).
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 85 |
| firefox | 79 |
| safari | 14 |
| edge | 85 |
| node | 15.0 |