The JavaScript Promise.all() method
The Promise.all() method takes an array of promises and returns a single promise that fulfills with an array of all their results — once they've all fulfilled. It runs them in parallel, so it's much faster than awaiting one at a time. If any promise rejects, the whole thing rejects immediately (fail-fast).
Overview
Promise.all() coordinates multiple asynchronous operations that don't depend on each other. You pass it an array of promises, and it returns one promise that resolves to an array of their results, in the same order — const [a, b, c] = await Promise.all([p1, p2, p3]). The big win is parallelism: the operations run at the same time, so three 1-second requests finish in about one second total, not three.
This is the standard fix for the common mistake of awaiting independent calls sequentially. const a = await fetchA(); const b = await fetchB(); waits for A to finish before even starting B. If they don't depend on each other, Promise.all([fetchA(), fetchB()]) starts both at once and is far faster.
The behavior to know is fail-fast: if any promise rejects, Promise.all() rejects right away with that error, and the other results are discarded. Wrap it in try...catch. When you instead want every outcome even if some fail, use Promise.allSettled(), which never rejects and reports each result's status. There's also Promise.race() (first to settle wins) and Promise.any() (first to fulfill).
Syntax
const results = await Promise.all([p1, p2, p3]);
// run independent requests in parallel
const [user, posts] = await Promise.all([
fetch("/user").then(r => r.json()),
fetch("/posts").then(r => r.json())
]);
Parameters
The Promise.all() method accepts the following parameters.
| Parameter | Description |
|---|---|
iterable |
An iterable (usually an array) of promises (or values). The result is an array of their resolved values, in order. |
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const wait = (val, ms) => new Promise(r => setTimeout(() => r(val), ms));
const out = document.getElementById('out');
const start = Date.now();
// both run in parallel (~600ms total, not 1000)
Promise.all([wait('A', 600), wait('B', 400)]).then(results => {
out.textContent = 'got [' + results.join(', ') + '] in ~' +
Math.round((Date.now() - start) / 100) * 100 + 'ms';
});
out.textContent = 'running in parallel...';
</script>
Best practices
- Use
Promise.all()to run independent async work in parallel instead of awaiting one at a time. - Wrap it in try...catch — it rejects as soon as any promise fails.
- Use
Promise.allSettled()when you need every result even if some reject. - Results come back in the order of the input array, not the order they finished.
Frequently asked questions
What does Promise.all() do?
What happens if one promise in Promise.all() fails?
Promise.allSettled() to get every outcome regardless.How is Promise.all() faster than awaiting separately?
What is the difference between Promise.all() and Promise.race()?
Promise.all() waits for all to fulfill; Promise.race() settles as soon as the first promise settles (fulfills or rejects).