Promise.all()
Waits for every promise in an iterable to fulfill, or rejects on the first failure.
Promise.all(iterable)- Added in JavaScript ES2015
Parameters
| Parameter | Type | Description |
|---|---|---|
$iterable | Iterable | An iterable, such as an Array, of promises. Values are awaited, so other thenables are resolved too; non-thenables are passed through as-is. |
Return value
PromiseA Promise that fulfills with an array of the fulfillment values in input order, regardless of completion order. It is already fulfilled if the iterable is empty, and rejects with the reason of the first promise to reject.
Errors
TypeError if the argument is not iterable.
Promise.all() runs work concurrently and gives you one promise for the whole batch. The result array matches input order, not completion order, so you can destructure it positionally without worrying about which finished first.
Fail-fast is the defining behaviour
The moment any input rejects, the combined promise rejects with that reason — it does not wait for the others. This is what you want when the results are useless without each other. It is not what you want when partial results are still valuable: use Promise.allSettled() there.
Crucially, rejecting does not cancel the remaining operations. Promises have no cancellation. Those requests keep running to completion, and their eventual results — successes and later rejections alike — are simply discarded. Those later rejections are not reported as unhandled, because all() attached its own handler to every input when it iterated them. If you need the work to actually stop, cancel it yourself with something like an AbortController.
Getting the concurrency you expect
The promises must already be started before all() sees them. Promise.all(ids.map(fetchOne)) is concurrent because map starts every call immediately. Awaiting each one inside a loop and collecting the values first is sequential — all() cannot parallelise work that has already finished.
Example
When to use it
- Load several independent resources before rendering a screen
- Fan out one request per id and collect the results in order
- Wait for a batch of writes to all complete before reporting success
- Resolve a mixed array of promises and plain values into plain values
Frequently asked questions
What is the difference between Promise.all and Promise.allSettled?
Promise.all rejects as soon as any input rejects and gives you only the values; Promise.allSettled always fulfills and gives you a status/value/reason record for every input. Use allSettled when partial success is still useful.
Does Promise.all cancel the other promises when one rejects?
No. There is no cancellation in the promise model — every operation you started runs to completion, and only the combined result is short-circuited.
Are the results in completion order or input order?
Input order, always. The array index of each result matches the index of its promise in the iterable, no matter which settled first.
More examples
Fail-fast, and what keeps running
The combined promise rejects after 10ms with the first failure only. The later 20ms and 50ms operations are not cancelled — the final line prints once they have all finished anyway.
const delay = (ms, v) => new Promise((res) => setTimeout(() => res(v), ms));
const boom = (ms, m) =>
new Promise((_, rej) => setTimeout(() => rej(new Error(m)), ms));
try {
await Promise.all([delay(50, "a"), boom(10, "first failure"), boom(20, "second failure")]);
} catch (e) {
console.log("rejected with:", e.message);
}
await delay(60);
console.log("both timers still ran to completion");Concurrency from map()
map() starts all three lookups immediately, so the batch takes as long as the slowest (30ms), not the sum (60ms), and the names come back in id order. The second line shows non-thenable values passing straight through unchanged.
const ids = [1, 2, 3];
const fetchName = (id) =>
new Promise((res) => setTimeout(() => res("user-" + id), 10 * id));
const names = await Promise.all(ids.map(fetchName));
console.log(names);
console.log(await Promise.all([1, [2], { a: 3 }]));
Discussion