combinator
Promise.all
Waits for all promises in an iterable to fulfill and resolves with an array of their values in original order. Rejects immediately with the reason of the first promise that rejects (fail-fast).
Promise.all(iterable) Parameters
| Parameter | Purpose |
|---|---|
| iterable | Any iterable of promises or values (non-promise values are wrapped) |
| returns | Promise<Array> resolved in input order, regardless of settle order |
| empty input | Resolves synchronously-microtask with [] when the iterable is empty |
Examples
const [users, posts] = await Promise.all([
fetch('/api/users').then(r => r.json()),
fetch('/api/posts').then(r => r.json())
]); Runs both fetches in parallel and destructures results in original order.
try {
const results = await Promise.all(ids.map(id => loadUser(id)));
} catch (err) {
console.error('At least one loadUser failed:', err);
} Fails fast — one rejection aborts the whole await; other promises still run but their results are discarded.
const mixed = await Promise.all([1, Promise.resolve(2), 3]);
console.log(mixed); // [1, 2, 3] Non-promise values pass through unchanged.
Gotcha
Rejects on the FIRST failure and never yields the other results — use Promise.allSettled if you need every outcome. Pending promises are not cancelled on rejection; they continue running in the background.
Related
Promise.allSettled
Waits for every promise to settle (fulfill or reject) and always resolves with an array of result descriptors. Each entry is either { status: 'fulfilled', value } or { status: 'rejected', reason }.
Promise.race
Settles as soon as the first promise in the iterable settles, adopting its state (fulfilled or rejected). The remaining promises keep running but their outcomes are ignored.
Promise.any
Resolves with the value of the first promise to fulfill, ignoring any rejections until a success occurs. If every promise rejects, it rejects with an AggregateError whose .errors array contains each reason.
← All JS Promise reference · async/await vs promises vs callbacks