monocart-reporter 2.9.6 → 2.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +1,74 @@
1
- class Concurrency {
2
-
3
- constructor(maxCount = 10) {
4
- this.maxCount = maxCount;
5
- this.list = [];
6
- }
7
-
8
- addItem(item) {
9
- this.list.push(item);
10
- }
11
-
12
- addList(list) {
13
- this.list = this.list.concat(list);
14
- }
15
-
16
- start(handler) {
17
- // must be async function
18
- if (typeof handler !== 'function') {
19
- return;
20
- }
21
- this.handler = handler;
22
- this.count = 0;
23
- return new Promise((resolve) => {
24
- this.resolve = resolve;
25
- this.next();
26
- });
27
- }
28
-
29
- next() {
30
- // console.log(`list: ${this.list.length} count: ${this.count}`);
31
-
32
- // if has clear
33
- if (!this.resolve) {
34
- return;
35
- }
36
-
37
- if (!this.list.length) {
38
- // no list but has in progress count
39
- if (this.count > 0) {
40
- return;
41
- }
42
- // all finish
43
- this.resolve();
44
- this.clear();
45
- return;
46
- }
47
-
48
- // out of concurrency count, just wait
49
- if (this.count >= this.maxCount) {
50
- return;
51
- }
52
-
53
- const item = this.list.shift();
54
- this.count += 1;
55
-
56
- // async handler
57
- this.handler(item).finally(() => {
58
- this.count -= 1;
59
- this.next();
60
- });
61
-
62
- this.next();
63
- }
64
-
65
- clear() {
66
- this.list = [];
67
- this.handler = null;
68
- this.count = 0;
69
- this.resolve = null;
70
- }
71
-
72
- }
73
-
74
- module.exports = Concurrency;
1
+ class Concurrency {
2
+
3
+ constructor(maxCount = 10) {
4
+ this.maxCount = maxCount;
5
+ this.list = [];
6
+ }
7
+
8
+ addItem(item) {
9
+ this.list.push(item);
10
+ }
11
+
12
+ addList(list) {
13
+ this.list = this.list.concat(list);
14
+ }
15
+
16
+ start(handler) {
17
+ // must be async function
18
+ if (typeof handler !== 'function') {
19
+ return;
20
+ }
21
+ this.handler = handler;
22
+ this.count = 0;
23
+ return new Promise((resolve) => {
24
+ this.resolve = resolve;
25
+ this.next();
26
+ });
27
+ }
28
+
29
+ next() {
30
+ // console.log(`list: ${this.list.length} count: ${this.count}`);
31
+
32
+ // if has clear
33
+ if (!this.resolve) {
34
+ return;
35
+ }
36
+
37
+ if (!this.list.length) {
38
+ // no list but has in progress count
39
+ if (this.count > 0) {
40
+ return;
41
+ }
42
+ // all finish
43
+ this.resolve();
44
+ this.clear();
45
+ return;
46
+ }
47
+
48
+ // out of concurrency count, just wait
49
+ if (this.count >= this.maxCount) {
50
+ return;
51
+ }
52
+
53
+ const item = this.list.shift();
54
+ this.count += 1;
55
+
56
+ // async handler
57
+ this.handler(item).finally(() => {
58
+ this.count -= 1;
59
+ this.next();
60
+ });
61
+
62
+ this.next();
63
+ }
64
+
65
+ clear() {
66
+ this.list = [];
67
+ this.handler = null;
68
+ this.count = 0;
69
+ this.resolve = null;
70
+ }
71
+
72
+ }
73
+
74
+ module.exports = Concurrency;