Implement promiseAll(items), your own version of Promise.all. Don't call Promise.all, Promise.allSettled, Promise.any or Promise.race.
items is an array of promises and plain values. Return a promise that follows these rules:
- It resolves with an array of the results in input order, whatever order they finish in.
- It treats a plain value as already resolved.
- It resolves with
[]for an empty array. - It rejects as soon as any item rejects, with that item's reason. It doesn't wait for the others.
Input: await promiseAll([wait(30, 'a'), 'b', Promise.resolve('c')])
Output: ['a', 'b', 'c']
Input: await promiseAll([])
Output: []
Input: await promiseAll([never, Promise.reject('x')])
Output: rejects with 'x'
never is a promise that never settles. The rejection doesn't wait for it.