Write Your Own Promise.allSettled
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write promiseAllSettled(items) without using Promise.all, Promise.allSettled, Promise.race or Promise.any. items is an array of promises and plain values, and a plain value counts as already resolved. Return a promise that waits until every item has settled, then resolves with an array in the same order as items: { status: "fulfilled", value } for each item that resolved and { status: "rejected", reason } for each that rejected. It never rejects, and an empty array resolves to an empty array.
Your code must pass
- Waits until every item has settled
- Describes each outcome, in input order
- Never rejects, even when every item fails
- Resolves an empty array to an empty array
- Works without the built-in Promise combinators