Promise.all()
The standard way to run several async operations at once. Its fail-fast behaviour is the right default and the source of its two traps: you lose the successful results, and the other operations keep running.
Demo
Each input is [outcome, value, delay in ms]: 'ok' fulfils with the value, anything else rejects with an Error carrying it. The first case finishes the second input first, yet the result is [1, 2] — input order, which is what makes destructuring safe. The third case is the fail-fast rule: the rejection after 10ms settles the whole thing, and the success still pending at 50ms is simply discarded — not cancelled, just ignored. An empty list resolves immediately with an empty array.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| iterable | iterable | yes | Any iterable, usually an array. Non-promise values are passed through as if already resolved, so a mixed array works. |
Return value
Promise<Array> — A Promise for an array of results in the ORDER OF THE INPUT, not the order they finished. Rejects as soon as any input rejects, with that first reason.
Common patterns
const [user, posts] = await Promise.all([ fetchUser(id), fetchPosts(id), ]);
const a = fetchA(); const b = fetchB(); const [ra, rb] = await Promise.all([a, b]);
const results = await Promise.allSettled(tasks);
Examples
Pitfalls
await Promise.all([ok1, ok2, failing])
const rs = await Promise.allSettled([ok1, ok2, failing]); rs.filter(r => r.status === "fulfilled")
await Promise.all([failing, slowFetch])
const c = new AbortController(); // pass c.signal to each fetch, then c.abort()
for (const u of urls) results.push(await fetch(u));
const results = await Promise.all(urls.map(u => fetch(u)));
await Promise.all([() => fetchA(), () => fetchB()])
await Promise.all([fetchA(), fetchB()])
When to use
- Several independent async operations that must all succeed
- Fetching data for one view from multiple endpoints
- Anywhere a loop currently awaits one item at a time
- Partial success is acceptable → allSettled
- You want the first result only → race, or any
- The operations depend on each other → sequential awaits are correct
- You need to cancel on failure → AbortController alongside
Notes
FAQ
It runs them CONCURRENTLY, which for I/O is what matters — the requests overlap. JavaScript is single-threaded, so nothing is parallel in the CPU sense. The promises must also already be in flight; Promise.all only waits.