@vbarbarosh/node-helpers 3.23.5 → 3.23.6
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.
- package/package.json +1 -1
- package/src/parallel.js +12 -2
package/package.json
CHANGED
package/src/parallel.js
CHANGED
|
@@ -8,6 +8,7 @@ async function parallel({concurrency, spawn, progress})
|
|
|
8
8
|
{
|
|
9
9
|
const running = [];
|
|
10
10
|
return new Promise(function (resolve, reject) {
|
|
11
|
+
let failed = false;
|
|
11
12
|
const timer = setInterval(tick, 1000);
|
|
12
13
|
schedule();
|
|
13
14
|
if (running.length) {
|
|
@@ -15,6 +16,9 @@ async function parallel({concurrency, spawn, progress})
|
|
|
15
16
|
}
|
|
16
17
|
function schedule() {
|
|
17
18
|
while (running.length < concurrency) {
|
|
19
|
+
if (failed) {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
18
22
|
const w = spawn();
|
|
19
23
|
if (!w) {
|
|
20
24
|
break;
|
|
@@ -22,6 +26,9 @@ async function parallel({concurrency, spawn, progress})
|
|
|
22
26
|
const item = Promise.resolve(w).then(resolved, rejected);
|
|
23
27
|
running.push(item);
|
|
24
28
|
function resolved() {
|
|
29
|
+
if (failed) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
25
32
|
const i = running.indexOf(item);
|
|
26
33
|
if (i === -1) {
|
|
27
34
|
throw new NotImplemented();
|
|
@@ -30,8 +37,11 @@ async function parallel({concurrency, spawn, progress})
|
|
|
30
37
|
schedule();
|
|
31
38
|
}
|
|
32
39
|
function rejected(error) {
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
if (failed) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
running.splice(0, running.length);
|
|
44
|
+
reject(error);
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
if (running.length === 0) {
|