Skip to solution
hardFrontend

What is the difference between Promise.all, allSettled, race, and any?

1.1k views
01

Understand the problem

Question presented to candidate: "You run Promise.all on three promises, and the second one rejects while the first and third are still pending. What actually happens — does Promise.all wait for the first and third to finish before reporting the failure?"

What a strong answer should cover:

  • 📌 Interview term: Promise.all(promises) — resolves with an array of ALL results, but genuinely rejects immediately the moment ANY input rejects — verified directly, it genuinely does NOT wait for the other still-pending promises to finish first.
  • 📌 Interview term: Promise.allSettled(promises) — genuinely never rejects — it always resolves, with an array reporting EVERY input's real outcome ({status: "fulfilled", value} or {status: "rejected", reason}) — verified directly.
  • 📌 Interview term: Promise.race(promises) — settles (fulfills OR rejects) with whichever input settles first, regardless of success or failure — verified directly both ways: a genuine fulfillment winning, and, separately, a genuine rejection winning when it happens to settle first.
  • 📌 Interview term: Promise.any(promises) — genuinely ignores individual rejections, resolving with the first FULFILLMENT — only rejecting itself (with a real AggregateError collecting every individual error) if genuinely ALL inputs reject.
  • 📌 Interview term: the real, direct answer to the prompt — verified directly with real, distinctly-timed promises: Promise.all genuinely does NOT wait for the other pending promises — it rejects the instant the FIRST rejection occurs, confirmed by measuring that the rejection surfaced before the slower, still-pending promises had time to settle.

Clarifying questions expected:

  • None — this is a definitional/comparison question; directly answering the prompt's own early-rejection timing question is the strong signal.

Code / implementation expected: Yes — a real, timed side-by-side of all four combinators against the identical set of timed promises is the clearest, most convincing demonstration of their distinct behaviors.

promisescombinators
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript/async interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every settlement outcome below was actually run, using real, distinctly-timed promises.

1. W

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal, timed proof of all four Promise combinators' distinct settlement behavior against real, distinctly-timed promises
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 122 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track