Glossary / Promise.all
Promise.all
Promise.all(iterable) converts an iterable of values/Promises into one Promise that fulfills with an array of fulfillment values in input order when every input fulfills. It rejects as soon as an input rejection is observed. It is the common combinator for independent operations that are all required, but it does not start operations itself beyond consuming already-created inputs and does not cancel siblings on failure.
Parallel independent work
const [profile, permissions] = await Promise.all([
fetchProfile(userId),
fetchPermissions(userId),
]);
Input order is preserved even when operations finish in a different order. Non-Promise values are treated as already fulfilled. An empty iterable fulfills immediately with an empty array. If one operation rejects, other operations may continue and produce effects; use AbortController or explicit cancellation coordination if stopping them matters.
Do not use Promise.all for dependent steps that need prior results; chain/await them sequentially. Be mindful of unbounded fan-out: constructing thousands of requests at once can overwhelm services and memory. Use a concurrency limiter for large collections. Errors should retain operation context so the failure can be diagnosed.
Interview questions
- In what order are fulfillment values returned? Input order, not completion order.
- When does it reject? When an input rejects and that rejection is observed.
- Does it cancel remaining tasks? No.
- What does Promise.all([]) fulfill with? An empty array.
- When not use it? Dependent operations or unbounded fan-out without concurrency control.