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