Promise combinators
You have several promises in flight and need one answer out of the batch: all of them, the first to settle, or the first to succeed. The choice matters most when one fails — some waits should keep going, some should stop.
A combinator takes many promises and returns one. Which you reach for depends on what should happen when they settle differently.
Promise.allfulfils with an array of every result, in input order, once all fulfil. It rejects as soon as the first promise rejects.Promise.allSettledalways fulfils, once every promise has settled, with an array of{ status: 'fulfilled', value }or{ status: 'rejected', reason }objects. Use it when one failure should not sink the batch.Promise.racesettles with the first promise to settle, whether it fulfils or rejects.Promise.anyfulfils with the first promise to fulfil, ignoring rejections. If every promise rejects, it rejects with anAggregateError.
Reach for Promise.all when every result is required and any failure should
abort the batch; Promise.allSettled when you want a full report of what
succeeded and what failed; Promise.race for a timeout or first-response-wins;
and Promise.any when the first success is enough. Each returns a single
promise, so you await one value and get back an array — or, for race and
any, the winning value itself.
const [user, posts] = await Promise.all([getUser(id), getPosts(id)]);
const results = await Promise.allSettled([a, b, c]);
You are about to answer a short quiz on the Promise combinators.