Promise.allSettled: every outcome
One failure didn't stop the other two parts from showing.
Four static methods combine many promises into one: all waits for every one (and fails fast), allSettled waits for every outcome, race takes the first to settle, and any takes the first success.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Using wait(ms, value), load "A" (100 ms), "B" (200 ms) and "C" (50 ms) in parallel and log [ 'A', 'B', 'C' ].
Write firstAnswer(promises) that fulfils with the first success, or with the string "no answer" if every promise fails.
Explain it without notes
Compare Promise.all, allSettled, race and any: what does each fulfil and reject with?
If Promise.all makes nothing run in parallel, why does using it make code faster?
How would you add a timeout to a promise, and what is the limitation of doing it with race?
What is an AggregateError, and when do you see one?
Preview
Console
Nothing logged yet.Expected console output
fulfilled Profile
rejected Orders unavailable
fulfilled Messages
{ status: 'rejected', reason: Error: Orders unavailable }