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 realAggregateErrorcollecting 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.allgenuinely 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.