Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/lib. A collection of common utilities I need. www.npmjs.com/package/@samual/lib
Something went wrong. Try again.
1234567891011121314151617181920export async function* raceAllPromises<T>(promises: Promise<T>[]): AsyncGenerator<T, void, void> { const promisesIndex = promises.map(promise => { type SelfReferencingPromise = Promise<{ value: T, promise: SelfReferencingPromise }>
const newPromise: SelfReferencingPromise = promise.then(value => ({ value, promise: newPromise }))
return newPromise })
while (promisesIndex.length) { // eslint-disable-next-line no-await-in-loop -- this is on purpose const { value, promise } = await Promise.race(promisesIndex)
yield value promisesIndex.splice(promisesIndex.indexOf(promise), 1) }}
export default raceAllPromises