Write Your Own Promise.race
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write promiseRace(items) without using Promise.race, Promise.all, Promise.allSettled or Promise.any. items is an array of promises and plain values, and a plain value counts as already resolved. Return a promise that settles the same way as the first item to settle: it resolves with that item's value or rejects with its reason, and ignores everything that settles after. Given an empty array, it stays pending for ever, as Promise.race does.
Your code must pass
- Resolves with the first value to arrive
- Rejects when the first to settle rejects
- Counts a plain value as already resolved
- Stays pending for an empty array
- Works without the built-in Promise combinators