Lesson 20 of 80
Four static Promise methods for running several promises together — and they disagree sharply on what counts as 'done' and what happens when one fails.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
You need to load 5 independent widgets and show whichever succeed, even if some fail. Which combinator fits?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
You already know a single promise settles as fulfilled or rejected. The combinators answer: given a list of promises, when is the whole group "done," and what do you get back?
const results = await Promise.all([p1, p2, p3]);
// resolves with [v1, v2, v3] IF ALL succeed
// rejects immediately with the FIRST rejection if any one fails — others keep running but their results are discarded
const results2 = await Promise.allSettled([p1, p2, p3]);
// always resolves, with [{status, value|reason}, ...] for every promise — never rejects
const first = await Promise.race([p1, p2, p3]);
// settles as soon as the FIRST promise settles, fulfilled or rejected — whichever happens first wins
const firstSuccess = await Promise.any([p1, p2, p3]);
// resolves with the first FULFILLED value; rejects only if ALL of them reject
| Combinator | Waits for | Fails when |
|---|---|---|
| all | everything to fulfill | any one rejects |
| allSettled | everything to settle | never — always tells you the outcome of each |
| race | the first to settle, either way | the first settled one was a rejection |
| any | the first to fulfill | every single one rejects |
Three promises: p1 resolves fast, p2 resolves slow, p3 rejects.
all vs allSettled is the one interviewers probe hardest. If you need every result even when some fail (e.g. "load these five independent widgets, show whichever succeed"), allSettled is correct — all would throw away all the successes the moment one fails.race isn't "the fastest wins" in a good sense necessarily — a fast rejection wins over a slow success. It's genuinely "first to settle," not "first to succeed."any is the newest of the four and is the one actually named for "first success" — it's what people often mean when they reach for race by mistake."You have 5 independent API calls — how do you run them concurrently and handle partial failure?" is a direct real-world question, and the honest answer requires knowing which combinator actually matches "some can fail, I still want the rest."