UNPKG

735 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3class WaitGroup {
4 constructor() {
5 this.total = 0;
6 this.done = 0;
7 this.callbacks = [];
8 }
9 add() {
10 this.total++;
11 return () => {
12 this.done++;
13 this.check();
14 };
15 }
16 waitAll(cb) {
17 if (this.total === this.done) {
18 cb();
19 return;
20 }
21 this.callbacks.push(cb);
22 }
23 check() {
24 if (this.total === this.done) {
25 this.noticeAll();
26 }
27 }
28 noticeAll() {
29 this.callbacks.forEach(cb => cb());
30 this.callbacks = [];
31 }
32}
33exports.WaitGroup = WaitGroup;
34//# sourceMappingURL=wait-group.js.map
\No newline at end of file