@4players/odin-common
Version:
A collection of commonly used type definitions and utility functions across ODIN web projects
19 lines (18 loc) • 581 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Selector = void 0;
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];
}
}
exports.Selector = Selector;