1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | class 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 | }
|
33 | exports.WaitGroup = WaitGroup;
|
34 |
|
\ | No newline at end of file |