What is the difference between Promise.all and Promise.allSettled?
Promise.all rejects as soon as any promise rejects and gives you results only if all succeed. Promise.allSettled always waits for every promise and reports each outcome as fulfilled or rejected.
Explain it simply
Suppose you send SMS reminders to five friends about a cricket match. With Promise.all, you say, "If even one message fails, I will treat the whole job as failed and stop caring about the rest." With Promise.allSettled, you say, "Try all five, then give me a report of who got it and who did not."
Example
const ok = (v) => Promise.resolve(v);
const fail = (m) => Promise.reject(new Error(m));
async function demo() {
try {
await Promise.all([ok(1), fail("net down"), ok(3)]);
} catch (e) {
console.log("all failed fast:", e.message); // all failed fast: net down
}
const results = await Promise.allSettled([ok(1), fail("net down"), ok(3)]);
console.log(results.map((r) => r.status));
// [ 'fulfilled', 'rejected', 'fulfilled' ]
}
demo();Each allSettled entry is { status: "fulfilled", value } or { status: "rejected", reason }.
Note: the other promises in Promise.all do not get cancelled when one rejects. They keep running; their results are just ignored.
Related helpers: Promise.race settles with the first promise to finish, and Promise.any resolves with the first success.
What to say in the interview
"Promise.all is all-or-nothing and fails fast. Promise.allSettled never rejects and gives per-item status. I use all when every result is required, and allSettled for independent jobs like sending notifications."
Common mistakes
- Using
Promise.allfor optional tasks and losing the successful results. - Assuming a rejection in
Promise.allcancels the other work.