UNPKG

@4players/odin-common

Version:

A collection of commonly used type definitions and utility functions across ODIN web projects

15 lines (14 loc) 455 B
export class Selector { constructor(_Generators) { this._Generators = _Generators; this._Futures = _Generators.map(Selector.addIndex); } async next() { const [result, index] = await Promise.race(this._Futures); this._Futures[index] = Selector.addIndex(this._Generators[index], index); return result; } static async addIndex(generator, index) { return [await generator(), index]; } }