Collecting outcomes with Promise.allSettled
How it works
Promise.allSettled(iterable) waits for each input to settle. Each output record has status: "fulfilled" and value, or status: "rejected" and reason. The records preserve input order. Individual input rejection becomes a record, not rejection of the aggregate under normal iteration. Errors while iterating the input itself can still reject the returned promise.
Example 1
Promise.allSettled([Promise.resolve(4), Promise.reject("missing")]).then(results => console.log(JSON.stringify(results)));Expected output in the tested environment:
[{"status":"fulfilled","value":4},{"status":"rejected","reason":"missing"}]Each outcome has its own shape.
Example 2
Expected output in the tested environment:
0An empty input has no outcome records.
Common mistake
Do not read result.value without checking status; a rejected record has reason instead.
Practice
Summarize fulfilled and rejected counts from a mix of three controlled outcomes; preserve the original input labels.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Collecting outcomes with Promise.allSettled — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
What does an individual rejected input become in a normal allSettled result?
Which combinator fits a report requiring every independent job outcome?
Can an error thrown by input iteration reject allSettled?
For Collecting outcomes with Promise.allSettled, what is the console output of example 1 in Node.js 22.16.0?
Promise.allSettled([Promise.resolve(4), Promise.reject("missing")]).then(results => console.log(JSON.stringify(results)));For Collecting outcomes with Promise.allSettled, what is the console output of example 2 in Node.js 22.16.0?
Promise.allSettled([]).then(r => console.log(r.length));