Promise.all
- Version
- es2025
- Since
- es2015
- Review
- Draft
Summary#
Promise.all combines an iterable of inputs into one promise. The combined promise fulfills when every input fulfills, with results in input order.
Syntax#
const results = await Promise.all([firstPromise, secondPromise]);
Example#
const result = await Promise.all([
Promise.resolve("headers"),
Promise.resolve("body"),
200,
]);
console.log(JSON.stringify(result));
Expected output#
["headers","body",200].
Common mistakes#
A rejection rejects the combined promise without cancelling the other operations. Use Promise.allSettled when you need every outcome. Pass promises or values, and call asynchronous functions beforehand to start their work.
Version applicability#
Promise.all was introduced in ES2015. The example uses ES2022 top-level await. Save it as an .mjs file to run it as a module in Node.js.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0