Write Your Own Promise.any
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Write promiseAny(items) without using Promise.any, Promise.all, Promise.allSettled or Promise.race. items is an array of promises and plain values, and a plain value counts as already resolved. Return a promise that resolves with the value of the first item to resolve, ignoring rejections along the way. If every item rejects, reject with an AggregateError whose errors array holds every reason in the same order as items, whatever order they rejected in. An empty array rejects with an AggregateError whose errors array is empty.
Your code must pass
- Resolves with the first value to arrive
- Waits past rejections for a value
- Rejects with an AggregateError of every reason, in input order
- Rejects an empty array with an AggregateError
- Works without the built-in Promise combinators