Engineering practice · 25 MIN
Preserve outcomes across asynchronous failures
Choose a failure policy before choosing a Promise combinator.
Promise.all rejects when one promise rejects, which is useful for all-or-nothing work. Promise.allSettled retains each result in input order. Neither combinator limits concurrency, cancels sibling work, or provides retries. Start operations deliberately and use AbortController when the underlying API supports cancellation. This exercise models independent requests without making network calls.
Treat the function as a small service: define a contract, maintain an invariant, and test the boundaries.
Read the example
Promise.allSettled([Promise.resolve(7), Promise.reject("offline")]).then(results => {
console.log(results.map(r => r.status).join(","));
});Check the expected output
fulfilled,rejected
Your challenge
Input is an array of {ok:boolean,value:JSON}. Turn each item into a resolved or rejected Promise. Return [{status:"ok",value}, {status:"error",value}, ...] in the original order; one rejection must not discard other results.
Solution cost: O(n) bookkeeping, plus the slowest operation’s latency. time · O(n) retained outcomes. space
Common trap
Adding async to map does not await the resulting array. Unbounded fan-out can overload upstream services.
Further reading: MDN: Promise.allSettled
Next lesson: Find the longest unique-character window →