Promise.all()
Waits for all promises to fulfill, or rejects as soon as one rejects.
Syntax
Promise.all(iterable)
Returns
Promise — A promise that fulfills with an array of results in input order, or
rejects with the first rejection.
Examples
Promise.all([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]).then(r => console.log(r));
Output
[ 1, 2, 3 ]
Promise.all([
Promise.resolve("a"),
Promise.reject(new Error("boom")),
]).catch(e => console.log(e.message));
Output
boom
Notes
- Results preserve the order of the input, not completion order.
- Rejects immediately ("fail fast") on the first rejection.
- Use `Promise.allSettled()` to wait for all regardless of failures.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 32 |
| firefox | 29 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |