Full answer
All four take an iterable of promises and return one promise, and they differ in when and how that promise settles.
Promise.all is all-or-nothing. If every input fulfills, the result is an array of values in input order (not completion order). If any input rejects, the result rejects immediately with that reason. The remaining promises keep running, but their results are ignored. Use it when every result is required.
Promise.allSettled never rejects. It waits for every input and returns an array of objects, each either { status: 'fulfilled', value } or { status: 'rejected', reason }. Use it when you want to report partial success, such as loading several widgets on a page.
Promise.race follows whichever promise settles first, whether it fulfills or rejects. The classic use is a timeout: race the real request against a promise that rejects after some milliseconds.
Promise.any follows the first fulfillment and ignores rejections until all have failed. Then it rejects with an AggregateError, whose errors property lists the reasons. Use it to try several mirrors of a resource and take the quickest success.
Non-promise values in the list are treated as already fulfilled. An empty list gives a fulfilled all and allSettled, a forever-pending race, and a rejected any.
const task = (ms, value, fail = false) =>
new Promise((resolve, reject) => setTimeout(() => (fail ? reject(new Error(value)) : resolve(value)), ms));
(async () => {
console.log(await Promise.all([task(30, 'slow'), task(10, 'fast'), 'plain value']));
try {
await Promise.all([task(10, 'a'), task(20, 'b failed', true)]);
} catch (error) {
console.log('all rejected with:', error.message);
}
const settled = await Promise.allSettled([task(10, 'ok'), task(20, 'bad', true)]);
console.log(settled.map((r) => (r.status === 'fulfilled' ? r.value : r.reason.message)));
console.log(await Promise.race([task(30, 'slow winner'), task(10, 'fast winner')]));
try {
await Promise.race([task(30, 'late'), task(10, 'early failure', true)]);
} catch (error) {
console.log('race rejected with:', error.message);
}
console.log(await Promise.any([task(10, 'mirror 1 down', true), task(30, 'mirror 2 ok')]));
try {
await Promise.any([task(10, 'x', true), task(20, 'y', true)]);
} catch (error) {
console.log(error.name, error.errors.map((e) => e.message));
}
const timeout = (ms) => new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), ms));
try {
await Promise.race([task(100, 'too slow'), timeout(20)]);
} catch (error) {
console.log('guarded call:', error.message);
}
})();Run with Node.js v24.22.1 as js-33.js; two runs gave identical output. Output: [ 'slow', 'fast', 'plain value' ] all rejected with: b failed [ 'ok', 'bad' ] fast winner race rejected with: early failure mirror 2 ok AggregateError [ 'x', 'y' ] guarded call: timeout
Key points
- all: every result in input order, or the first rejection.
- allSettled: waits for all and never rejects; reports status for each.
- race: first to settle wins, success or failure.
- any: first success wins; AggregateError if all fail.
- Rejection in all or race does not cancel the other promises.
Common mistakes
- Using Promise.all when partial results are acceptable, so one failure hides the other data.
- Assuming a rejected Promise.all cancels the other tasks; they continue and may still cause side effects.
- Expecting results of all in completion order instead of input order.
- Using Promise.race for a timeout and forgetting to clear the timer afterwards, which keeps the process alive.
Follow-ups
- How would you limit how many promises run at the same time?
- How can you cancel the slow request when a race is lost?
- What does Promise.all do with an empty array?
Tips
- Give one sentence on each method, then a use case: required data, partial success, timeout, fastest mirror.
- Mention that none of them cancel work; AbortController does that.
- Use a table in your head: waits for all or first, and how failures are handled.