UNPKG

@beenotung/tslib

Version:
35 lines 763 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WaitGroup = void 0; class WaitGroup { constructor() { this.total = 0; this.done = 0; this.callbacks = []; } add() { this.total++; return () => { this.done++; this.check(); }; } waitAll(cb) { if (this.total === this.done) { cb(); return; } this.callbacks.push(cb); } check() { if (this.total === this.done) { this.noticeAll(); } } noticeAll() { this.callbacks.forEach(cb => cb()); this.callbacks = []; } } exports.WaitGroup = WaitGroup; //# sourceMappingURL=wait-group.js.map