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

← All JS Promise reference · async/await vs promises vs callbacks