Promises in depth · core
Promise.all, allSettled, race and any
Promise.all fulfills with all values in input order or rejects on the first rejection, allSettled waits for everything and never rejects, race settles with the first promise to settle, and any fulfills with the first success or rejects with an AggregateError if all fail.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- All four accept any iterable. Non-promise values count as already fulfilled (Promise.resolve).
- all: results are in input order, not finish order. It rejects on the first rejection, and the other promises keep running (nothing is cancelled).
- allSettled: an array of { status: 'fulfilled', value } or { status: 'rejected', reason }.
- race: the first to settle wins, success or failure. A race-based timeout stops waiting but doesn't stop the request; use AbortSignal.timeout for that.
- any: the first success wins; if all reject, it rejects with AggregateError whose errors array is in input order.
- Empty input: all and allSettled resolve to [], any rejects with AggregateError, race stays pending forever.
- The promises are already running when you pass them in; combinators only wait. To limit concurrency you must control when tasks start (a pool).
- Promise.try(fn) (ES2025) runs fn and turns a sync return or throw into a promise.
The red pen
Common traps: mistake → fix
Mistake: Promise.all runs the promises in parallel
Fix: they were already started; all only waits.
Mistake: Promise.all cancels the rest on failure
Fix: nothing is cancelled.
Mistake: Promise.race([]) rejects
Fix: it stays pending forever.
Easy to hard
Questions interviewers ask, easy to hard
- Compare all, allSettled, race and any.
- A dashboard has five independent widgets. Which one do you use, and why?
- What does each return for an empty array?
- What does any reject with?
- Build a timeout with race. Why is AbortSignal better? When is Promise.try useful?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.