@vbarbarosh/node-helpers 3.23.5 → 3.24.0
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/src/shell_spawn.js +27 -21
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) {
|
package/src/shell_spawn.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
|
+
const Promise = require('bluebird');
|
|
1
2
|
const child_process = require('child_process');
|
|
2
3
|
|
|
3
4
|
function shell_spawn(args, options)
|
|
4
5
|
{
|
|
5
|
-
let promise;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let init, promise;
|
|
7
|
+
const out = child_process.spawn(args[0], args.slice(1), options);
|
|
8
|
+
out.init = function () {
|
|
9
|
+
return init = init || new Promise(function (resolve, reject) {
|
|
10
|
+
out.once('error', init_error);
|
|
11
|
+
out.once('spawn', init_spawn);
|
|
12
|
+
function init_error(error) {
|
|
13
|
+
out.off('spawn', init_spawn);
|
|
14
|
+
reject(error);
|
|
15
|
+
}
|
|
16
|
+
function init_spawn() {
|
|
17
|
+
out.off('error', init_error);
|
|
18
|
+
resolve(out);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
out.promise = function () {
|
|
9
23
|
return promise = promise || new Promise(function (resolve, reject) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
proc.off('error', on_error);
|
|
16
|
-
proc.off('exit', on_exit);
|
|
17
|
-
reject(error);
|
|
18
|
-
}
|
|
24
|
+
out.once('error', promise_error);
|
|
25
|
+
out.once('exit', promise_exit);
|
|
26
|
+
function promise_error(error) {
|
|
27
|
+
out.off('exit', promise_exit);
|
|
28
|
+
reject(error);
|
|
19
29
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
proc.off('error', on_error);
|
|
24
|
-
proc.off('exit', on_exit);
|
|
25
|
-
resolve({code, signal});
|
|
26
|
-
}
|
|
30
|
+
function promise_exit(code, signal) {
|
|
31
|
+
out.off('error', promise_error);
|
|
32
|
+
resolve({code, signal});
|
|
27
33
|
}
|
|
28
34
|
});
|
|
29
35
|
};
|
|
30
|
-
return
|
|
36
|
+
return out;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
module.exports = shell_spawn;
|