@beenotung/tslib
Version:
utils library in Typescript
33 lines (32 loc) • 672 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitGroup = void 0;
class WaitGroup {
total = 0;
done = 0;
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;