Promise.all()

Waits for all promises to fulfill, or rejects as soon as one rejects.

Since ES2015 (ES6) Spec ↗

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

EnvironmentSince version
chrome 32
firefox 29
safari 8
edge 12
node 0.12

See also