@stdlib/utils-parallel 0.0.6 → 0.2.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/CITATION.cff +30 -0
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +40 -52
- package/dist/index.d.ts +3 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/lib/browser/index.js +1 -1
- package/lib/defaults.js +30 -18
- package/lib/index.js +2 -2
- package/lib/main.js +5 -5
- package/lib/node/exec.js +5 -4
- package/lib/validate.js +9 -8
- package/package.json +19 -29
- package/bin/cli +0 -105
- package/docs/repl.txt +0 -68
- package/docs/types/test.ts +0 -164
- package/docs/usage.txt +0 -15
- package/etc/cli_opts.json +0 -23
package/lib/defaults.js
CHANGED
|
@@ -25,31 +25,43 @@ var numCPUs = require( '@stdlib/os-num-cpus' );
|
|
|
25
25
|
|
|
26
26
|
// MAIN //
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Returns default options.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @returns {Object} default options
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* var o = defaults();
|
|
36
|
+
* // returns {...}
|
|
37
|
+
*/
|
|
38
|
+
function defaults() {
|
|
39
|
+
return {
|
|
40
|
+
// Number of workers:
|
|
41
|
+
'workers': numCPUs - 1,
|
|
32
42
|
|
|
33
|
-
// Number of scripts to execute concurrently:
|
|
34
|
-
|
|
43
|
+
// Number of scripts to execute concurrently:
|
|
44
|
+
'concurrency': numCPUs - 1,
|
|
35
45
|
|
|
36
|
-
// Executable file/command:
|
|
37
|
-
|
|
46
|
+
// Executable file/command:
|
|
47
|
+
'cmd': 'node',
|
|
38
48
|
|
|
39
|
-
// Boolean indicating whether script output can be interleaved or must be ordered:
|
|
40
|
-
|
|
49
|
+
// Boolean indicating whether script output can be interleaved or must be ordered:
|
|
50
|
+
'ordered': false,
|
|
41
51
|
|
|
42
|
-
// Process user identity:
|
|
43
|
-
|
|
52
|
+
// Process user identity:
|
|
53
|
+
'uid': null,
|
|
44
54
|
|
|
45
|
-
// Process group identity:
|
|
46
|
-
|
|
55
|
+
// Process group identity:
|
|
56
|
+
'gid': null,
|
|
47
57
|
|
|
48
|
-
// `stdio` encoding:
|
|
49
|
-
|
|
58
|
+
// `stdio` encoding:
|
|
59
|
+
'encoding': 'buffer',
|
|
50
60
|
|
|
51
|
-
// Max child process `stdio` buffer size:
|
|
52
|
-
|
|
61
|
+
// Max child process `stdio` buffer size:
|
|
62
|
+
'maxBuffer': 200 * 1024 * 1024 // bytes
|
|
63
|
+
};
|
|
64
|
+
}
|
|
53
65
|
|
|
54
66
|
|
|
55
67
|
// EXPORTS //
|
package/lib/index.js
CHANGED
package/lib/main.js
CHANGED
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
var path = require( 'path' );
|
|
24
24
|
var isStringArray = require( '@stdlib/assert-is-string-array' ).primitives;
|
|
25
25
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
26
|
+
var format = require( '@stdlib/string-format' );
|
|
26
27
|
var cwd = require( '@stdlib/process-cwd' );
|
|
27
|
-
var copy = require( '@stdlib/utils-copy' );
|
|
28
28
|
var defaults = require( './defaults.js' );
|
|
29
29
|
var validate = require( './validate.js' );
|
|
30
30
|
var exec = require( './node' );
|
|
@@ -45,7 +45,7 @@ var exec = require( './node' );
|
|
|
45
45
|
* @param {NonNegativeInteger} [options.gid] - process group identity
|
|
46
46
|
* @param {NonNegativeInteger} [options.maxBuffer=200*1024*1024] - max child process `stdio` buffer size
|
|
47
47
|
* @param {Callback} clbk - callback to invoke after executing all scripts
|
|
48
|
-
* @throws {TypeError} first argument must be
|
|
48
|
+
* @throws {TypeError} first argument must be an array of strings
|
|
49
49
|
* @throws {TypeError} options argument must be an object
|
|
50
50
|
* @throws {TypeError} must provide valid options
|
|
51
51
|
* @throws {TypeError} callback argument must be a function
|
|
@@ -77,10 +77,10 @@ function parallel() {
|
|
|
77
77
|
|
|
78
78
|
files = arguments[ 0 ];
|
|
79
79
|
if ( !isStringArray( files ) ) {
|
|
80
|
-
throw new TypeError( 'invalid argument. First argument must be an array of
|
|
80
|
+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
|
|
81
81
|
}
|
|
82
82
|
files = files.slice();
|
|
83
|
-
opts =
|
|
83
|
+
opts = defaults();
|
|
84
84
|
if ( arguments.length > 2 ) {
|
|
85
85
|
options = arguments[ 1 ];
|
|
86
86
|
clbk = arguments[ 2 ];
|
|
@@ -92,7 +92,7 @@ function parallel() {
|
|
|
92
92
|
clbk = arguments[ 1 ];
|
|
93
93
|
}
|
|
94
94
|
if ( !isFunction( clbk ) ) {
|
|
95
|
-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value:
|
|
95
|
+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
|
|
96
96
|
}
|
|
97
97
|
// Prevent the number of concurrent scripts exceeding the number of actual scripts to run.
|
|
98
98
|
if ( opts.concurrency > files.length ) {
|
package/lib/node/exec.js
CHANGED
|
@@ -24,6 +24,7 @@ var fork = require( 'child_process' ).fork;
|
|
|
24
24
|
var path = require( 'path' );
|
|
25
25
|
var logger = require( 'debug' );
|
|
26
26
|
var objectKeys = require( '@stdlib/utils-keys' );
|
|
27
|
+
var format = require( '@stdlib/string-format' );
|
|
27
28
|
var getOpts = require( './options.js' );
|
|
28
29
|
|
|
29
30
|
|
|
@@ -92,7 +93,7 @@ function exec( files, opts, clbk ) {
|
|
|
92
93
|
idx = -1;
|
|
93
94
|
for ( i = 0; i < opts.concurrency; i++ ) {
|
|
94
95
|
pid = pids[ i%pids.length ];
|
|
95
|
-
next( workers[ pid ] ); // eslint-disable-line callback-return
|
|
96
|
+
next( workers[ pid ] ); // eslint-disable-line node/callback-return
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
/**
|
|
@@ -181,7 +182,7 @@ function exec( files, opts, clbk ) {
|
|
|
181
182
|
numClosed += 1;
|
|
182
183
|
debug( '%d of %d child processes have closed.', numClosed, opts.workers );
|
|
183
184
|
if ( numClosed === opts.workers ) {
|
|
184
|
-
done(); // eslint-disable-line callback-return
|
|
185
|
+
done(); // eslint-disable-line node/callback-return
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
|
|
@@ -286,9 +287,9 @@ function exec( files, opts, clbk ) {
|
|
|
286
287
|
return;
|
|
287
288
|
}
|
|
288
289
|
if ( code !== null && code !== 0 ) {
|
|
289
|
-
error = new Error( 'Child process failed with exit code: '
|
|
290
|
+
error = new Error( format( 'unexpected error. Child process failed with exit code: `%u`.', code ) );
|
|
290
291
|
} else if ( signal !== null ) {
|
|
291
|
-
error = new Error( 'Child process failed due to termination signal: '
|
|
292
|
+
error = new Error( format( 'unexpected error. Child process failed due to termination signal: `%s`.', signal ) );
|
|
292
293
|
}
|
|
293
294
|
if ( error ) {
|
|
294
295
|
error.code = code;
|
package/lib/validate.js
CHANGED
|
@@ -26,6 +26,7 @@ var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimit
|
|
|
26
26
|
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
|
|
27
27
|
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
28
28
|
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
29
|
+
var format = require( '@stdlib/string-format' );
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
// MAIN //
|
|
@@ -58,48 +59,48 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
|
58
59
|
*/
|
|
59
60
|
function validate( opts, options ) {
|
|
60
61
|
if ( !isObject( options ) ) {
|
|
61
|
-
return new TypeError( 'invalid argument. Options argument must be an object. Value:
|
|
62
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
62
63
|
}
|
|
63
64
|
if ( hasOwnProp( options, 'concurrency' ) ) {
|
|
64
65
|
opts.concurrency = options.concurrency;
|
|
65
66
|
if ( !isPositiveInteger( opts.concurrency ) ) {
|
|
66
|
-
return new TypeError( 'invalid option. `
|
|
67
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'concurrency', opts.concurrency ) );
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
if ( hasOwnProp( options, 'workers' ) ) {
|
|
70
71
|
opts.workers = options.workers;
|
|
71
72
|
if ( !isPositiveInteger( opts.workers ) ) {
|
|
72
|
-
return new TypeError( 'invalid option. `
|
|
73
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'workers', opts.workers ) );
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
if ( hasOwnProp( options, 'cmd' ) ) {
|
|
76
77
|
opts.cmd = options.cmd;
|
|
77
78
|
if ( !isString( opts.cmd ) ) {
|
|
78
|
-
return new TypeError( 'invalid option. `
|
|
79
|
+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'cmd', opts.cmd ) );
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
if ( hasOwnProp( options, 'ordered' ) ) {
|
|
82
83
|
opts.ordered = options.ordered;
|
|
83
84
|
if ( !isBoolean( opts.ordered ) ) {
|
|
84
|
-
return new TypeError( 'invalid option. `
|
|
85
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'ordered', opts.ordered ) );
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
if ( hasOwnProp( options, 'uid' ) ) {
|
|
88
89
|
opts.uid = options.uid;
|
|
89
90
|
if ( !isNonNegativeInteger( opts.uid ) ) {
|
|
90
|
-
return new TypeError( 'invalid option. `
|
|
91
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'uid', opts.uid ) );
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
if ( hasOwnProp( options, 'gid' ) ) {
|
|
94
95
|
opts.gid = options.gid;
|
|
95
96
|
if ( !isNonNegativeInteger( opts.gid ) ) {
|
|
96
|
-
return new TypeError( 'invalid option. `
|
|
97
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'gid', opts.gid ) );
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
if ( hasOwnProp( options, 'maxBuffer' ) ) {
|
|
100
101
|
opts.maxBuffer = options.maxBuffer;
|
|
101
102
|
if ( !isNonNegativeInteger( opts.maxBuffer ) ) {
|
|
102
|
-
return new TypeError( 'invalid option. `
|
|
103
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'maxBuffer', opts.maxBuffer ) );
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-parallel",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Execute scripts in parallel.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
|
-
"bin": {
|
|
17
|
-
"parallel": "./bin/cli"
|
|
18
|
-
},
|
|
19
16
|
"main": "./lib",
|
|
20
|
-
"browser":
|
|
17
|
+
"browser": {
|
|
18
|
+
"./lib": "./lib/browser/index.js",
|
|
19
|
+
"process": "process/"
|
|
20
|
+
},
|
|
21
21
|
"directories": {
|
|
22
22
|
"doc": "./docs",
|
|
23
23
|
"example": "./examples",
|
|
@@ -39,33 +39,23 @@
|
|
|
39
39
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@stdlib/assert-has-own-property": "^0.0
|
|
43
|
-
"@stdlib/assert-is-boolean": "^0.0
|
|
44
|
-
"@stdlib/assert-is-function": "^0.0
|
|
45
|
-
"@stdlib/assert-is-nonnegative-integer": "^0.0
|
|
46
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
47
|
-
"@stdlib/assert-is-positive-integer": "^0.0
|
|
48
|
-
"@stdlib/assert-is-string": "^0.0
|
|
49
|
-
"@stdlib/assert-is-string-array": "^0.0
|
|
50
|
-
"@stdlib/
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/
|
|
53
|
-
"@stdlib/process-cwd": "^0.0.x",
|
|
54
|
-
"@stdlib/process-env": "^0.0.x",
|
|
55
|
-
"@stdlib/utils-copy": "^0.0.x",
|
|
56
|
-
"@stdlib/utils-keys": "^0.0.x",
|
|
57
|
-
"debug": "^2.6.9"
|
|
42
|
+
"@stdlib/assert-has-own-property": "^0.1.0",
|
|
43
|
+
"@stdlib/assert-is-boolean": "^0.1.0",
|
|
44
|
+
"@stdlib/assert-is-function": "^0.1.0",
|
|
45
|
+
"@stdlib/assert-is-nonnegative-integer": "^0.1.0",
|
|
46
|
+
"@stdlib/assert-is-plain-object": "^0.1.0",
|
|
47
|
+
"@stdlib/assert-is-positive-integer": "^0.1.0",
|
|
48
|
+
"@stdlib/assert-is-string": "^0.1.0",
|
|
49
|
+
"@stdlib/assert-is-string-array": "^0.1.0",
|
|
50
|
+
"@stdlib/os-num-cpus": "^0.1.0",
|
|
51
|
+
"@stdlib/process-cwd": "^0.1.0",
|
|
52
|
+
"@stdlib/string-format": "^0.1.0"
|
|
58
53
|
},
|
|
59
54
|
"devDependencies": {
|
|
60
|
-
"@stdlib/fs-unlink": "^0.0.x",
|
|
61
|
-
"@stdlib/fs-write-file": "^0.0.x",
|
|
62
|
-
"@stdlib/random-base-minstd": "^0.0.x",
|
|
63
|
-
"@stdlib/utils-next-tick": "^0.0.x",
|
|
64
|
-
"@stdlib/utils-noop": "^0.0.x",
|
|
65
55
|
"proxyquire": "^2.0.0",
|
|
66
56
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
67
57
|
"istanbul": "^0.4.1",
|
|
68
|
-
"tap-
|
|
58
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
69
59
|
},
|
|
70
60
|
"engines": {
|
|
71
61
|
"node": ">=0.10.0",
|
|
@@ -111,7 +101,7 @@
|
|
|
111
101
|
],
|
|
112
102
|
"__stdlib__": {},
|
|
113
103
|
"funding": {
|
|
114
|
-
"type": "
|
|
115
|
-
"url": "https://
|
|
104
|
+
"type": "opencollective",
|
|
105
|
+
"url": "https://opencollective.com/stdlib"
|
|
116
106
|
}
|
|
117
107
|
}
|
package/bin/cli
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @license Apache-2.0
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2018 The Stdlib Authors.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
// MODULES //
|
|
24
|
-
|
|
25
|
-
var resolve = require( 'path' ).resolve;
|
|
26
|
-
var readFileSync = require( '@stdlib/fs-read-file' ).sync;
|
|
27
|
-
var CLI = require( '@stdlib/cli-ctor' );
|
|
28
|
-
var parallel = require( './../lib' );
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// FUNCTIONS //
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Callback invoked upon executing all scripts.
|
|
35
|
-
*
|
|
36
|
-
* @private
|
|
37
|
-
* @param {Error} [error] - error object
|
|
38
|
-
* @throws {Error} unexpected error
|
|
39
|
-
*/
|
|
40
|
-
function done( error ) {
|
|
41
|
-
if ( error ) {
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// MAIN //
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Main execution sequence.
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
function main() {
|
|
55
|
-
var flags;
|
|
56
|
-
var args;
|
|
57
|
-
var opts;
|
|
58
|
-
var cli;
|
|
59
|
-
|
|
60
|
-
// Create a command-line interface:
|
|
61
|
-
cli = new CLI({
|
|
62
|
-
'pkg': require( './../package.json' ),
|
|
63
|
-
'options': require( './../etc/cli_opts.json' ),
|
|
64
|
-
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
65
|
-
'encoding': 'utf8'
|
|
66
|
-
})
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Get any provided command-line options:
|
|
70
|
-
flags = cli.flags();
|
|
71
|
-
if ( flags.help || flags.version ) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Get any command-line arguments:
|
|
76
|
-
args = cli.args();
|
|
77
|
-
|
|
78
|
-
opts = {};
|
|
79
|
-
if ( flags.cmd ) {
|
|
80
|
-
opts.cmd = flags.cmd;
|
|
81
|
-
}
|
|
82
|
-
if ( flags.workers ) {
|
|
83
|
-
opts.workers = parseInt( flags.workers, 10 );
|
|
84
|
-
}
|
|
85
|
-
if ( flags.concurrency ) {
|
|
86
|
-
opts.concurrency = parseInt( flags.concurrency, 10 );
|
|
87
|
-
}
|
|
88
|
-
if ( flags.ordered ) {
|
|
89
|
-
opts.ordered = flags.ordered;
|
|
90
|
-
}
|
|
91
|
-
if ( flags.uid ) {
|
|
92
|
-
opts.uid = parseInt( flags.uid, 10 );
|
|
93
|
-
}
|
|
94
|
-
if ( flags.gid ) {
|
|
95
|
-
opts.gid = parseInt( flags.gid, 10 );
|
|
96
|
-
}
|
|
97
|
-
if ( flags.maxbuffer ) {
|
|
98
|
-
opts.maxBuffer = parseInt( flags.maxbuffer, 10 );
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Run main:
|
|
102
|
-
parallel( args, opts, done );
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
main();
|
package/docs/repl.txt
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( files, [options,] clbk )
|
|
3
|
-
Executes scripts in parallel.
|
|
4
|
-
|
|
5
|
-
Relative file paths are resolved relative to the current working directory.
|
|
6
|
-
|
|
7
|
-
Ordered script output does not imply that scripts are executed in order. To
|
|
8
|
-
preserve script order, execute the scripts sequentially via some other
|
|
9
|
-
means.
|
|
10
|
-
|
|
11
|
-
Parameters
|
|
12
|
-
----------
|
|
13
|
-
files: Array<string>
|
|
14
|
-
Script file paths.
|
|
15
|
-
|
|
16
|
-
options: Object (optional)
|
|
17
|
-
Options.
|
|
18
|
-
|
|
19
|
-
options.cmd: string (optional)
|
|
20
|
-
Executable file/command. Default: `'node'`.
|
|
21
|
-
|
|
22
|
-
options.concurrency: integer (optional)
|
|
23
|
-
Number of scripts to execute concurrently. Script concurrency cannot
|
|
24
|
-
exceed the number of scripts. By specifying a concurrency greater than
|
|
25
|
-
the number of workers, a worker may be executing more than `1` script at
|
|
26
|
-
any one time. While not likely to be advantageous for synchronous
|
|
27
|
-
scripts, setting a higher concurrency may be advantageous for scripts
|
|
28
|
-
performing asynchronous tasks. If the script concurrency is less than
|
|
29
|
-
the number of workers, the number of workers is reduced to match the
|
|
30
|
-
specified concurrency. Default: `options.workers`.
|
|
31
|
-
|
|
32
|
-
options.workers: integer (optional)
|
|
33
|
-
Number of workers. Default: number of CPUs minus `1`.
|
|
34
|
-
|
|
35
|
-
options.ordered: boolean (optional)
|
|
36
|
-
Boolean indicating whether to preserve the order of script output. By
|
|
37
|
-
default, the `stdio` output for each script is interleaved; i.e., the
|
|
38
|
-
`stdio` output from one script may be interleaved with the `stdio`
|
|
39
|
-
output from one or more other scripts. To preserve the `stdio` output
|
|
40
|
-
order for each script, set the `ordered` option to `true`. Default:
|
|
41
|
-
`false`.
|
|
42
|
-
|
|
43
|
-
options.uid: integer (optional)
|
|
44
|
-
Process user identity.
|
|
45
|
-
|
|
46
|
-
options.gid: integer (optional)
|
|
47
|
-
Process group identity.
|
|
48
|
-
|
|
49
|
-
options.maxBuffer: integer (optional)
|
|
50
|
-
Max child process `stdio` buffer size. This option is only applied when
|
|
51
|
-
`options.ordered = true`. Default: `200*1024*1024`.
|
|
52
|
-
|
|
53
|
-
clbk: Function
|
|
54
|
-
Callback to invoke after executing all scripts.
|
|
55
|
-
|
|
56
|
-
Examples
|
|
57
|
-
--------
|
|
58
|
-
> function done( error ) { if ( error ) { throw error; } };
|
|
59
|
-
> var files = [ './a.js', './b.js' ];
|
|
60
|
-
> {{alias}}( files, done );
|
|
61
|
-
|
|
62
|
-
// Specify the number of workers:
|
|
63
|
-
> var opts = { 'workers': 8 };
|
|
64
|
-
> {{alias}}( files, opts, done );
|
|
65
|
-
|
|
66
|
-
See Also
|
|
67
|
-
--------
|
|
68
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import parallel = require( './index' );
|
|
20
|
-
|
|
21
|
-
const done = ( error: Error ) => {
|
|
22
|
-
if ( error ) {
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// TESTS //
|
|
28
|
-
|
|
29
|
-
// The function returns an array of indices, element values, or arrays of index-value pairs...
|
|
30
|
-
{
|
|
31
|
-
const files = [ './a.js', './b.js ' ];
|
|
32
|
-
parallel( files, done );
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// The compiler throws an error if the function is provided a first argument which is not an array of strings...
|
|
36
|
-
{
|
|
37
|
-
parallel( 'abc', done ); // $ExpectError
|
|
38
|
-
parallel( {}, done ); // $ExpectError
|
|
39
|
-
parallel( null, done ); // $ExpectError
|
|
40
|
-
parallel( true, done ); // $ExpectError
|
|
41
|
-
parallel( false, done ); // $ExpectError
|
|
42
|
-
parallel( 5, done ); // $ExpectError
|
|
43
|
-
parallel( ( x: number ): number => x, done ); // $ExpectError
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// The compiler throws an error if the function is provided a last argument which is not a function...
|
|
47
|
-
{
|
|
48
|
-
const files = [ './a.js', './b.js ' ];
|
|
49
|
-
parallel( files, false ); // $ExpectError
|
|
50
|
-
parallel( files, true ); // $ExpectError
|
|
51
|
-
parallel( files, 32 ); // $ExpectError
|
|
52
|
-
parallel( files, 'abc' ); // $ExpectError
|
|
53
|
-
parallel( files, [] ); // $ExpectError
|
|
54
|
-
parallel( files, {} ); // $ExpectError
|
|
55
|
-
|
|
56
|
-
parallel( files, {}, false ); // $ExpectError
|
|
57
|
-
parallel( files, {}, true ); // $ExpectError
|
|
58
|
-
parallel( files, {}, 32 ); // $ExpectError
|
|
59
|
-
parallel( files, {}, 'abc' ); // $ExpectError
|
|
60
|
-
parallel( files, {}, [] ); // $ExpectError
|
|
61
|
-
parallel( files, {}, {} ); // $ExpectError
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// The compiler throws an error if the function is provided an options argument which is not an object...
|
|
65
|
-
{
|
|
66
|
-
const files = [ './a.js', './b.js ' ];
|
|
67
|
-
parallel( files, null, done ); // $ExpectError
|
|
68
|
-
parallel( files, 123, done ); // $ExpectError
|
|
69
|
-
parallel( files, false, done ); // $ExpectError
|
|
70
|
-
parallel( files, true, done ); // $ExpectError
|
|
71
|
-
parallel( files, [], done ); // $ExpectError
|
|
72
|
-
parallel( files, ( x: number ): number => x, done ); // $ExpectError
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The compiler throws an error if the function is provided a `cmd` option which is not a string...
|
|
76
|
-
{
|
|
77
|
-
const files = [ './a.js', './b.js ' ];
|
|
78
|
-
parallel( files, { 'cmd': false }, done ); // $ExpectError
|
|
79
|
-
parallel( files, { 'cmd': true }, done ); // $ExpectError
|
|
80
|
-
parallel( files, { 'cmd': null }, done ); // $ExpectError
|
|
81
|
-
parallel( files, { 'cmd': 123 }, done ); // $ExpectError
|
|
82
|
-
parallel( files, { 'cmd': [] }, done ); // $ExpectError
|
|
83
|
-
parallel( files, { 'cmd': {} }, done ); // $ExpectError
|
|
84
|
-
parallel( files, { 'cmd': ( x: number ): number => x }, done ); // $ExpectError
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// The compiler throws an error if the function is provided a `workers` option which is not a number...
|
|
88
|
-
{
|
|
89
|
-
const files = [ './a.js', './b.js ' ];
|
|
90
|
-
parallel( files, { 'workers': 'abc' }, done ); // $ExpectError
|
|
91
|
-
parallel( files, { 'workers': false }, done ); // $ExpectError
|
|
92
|
-
parallel( files, { 'workers': true }, done ); // $ExpectError
|
|
93
|
-
parallel( files, { 'workers': null }, done ); // $ExpectError
|
|
94
|
-
parallel( files, { 'workers': [] }, done ); // $ExpectError
|
|
95
|
-
parallel( files, { 'workers': {} }, done ); // $ExpectError
|
|
96
|
-
parallel( files, { 'workers': ( x: number ): number => x }, done ); // $ExpectError
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// The compiler throws an error if the function is provided a `concurrency` option which is not a number...
|
|
100
|
-
{
|
|
101
|
-
const files = [ './a.js', './b.js ' ];
|
|
102
|
-
parallel( files, { 'concurrency': 'abc' }, done ); // $ExpectError
|
|
103
|
-
parallel( files, { 'concurrency': false }, done ); // $ExpectError
|
|
104
|
-
parallel( files, { 'concurrency': true }, done ); // $ExpectError
|
|
105
|
-
parallel( files, { 'concurrency': null }, done ); // $ExpectError
|
|
106
|
-
parallel( files, { 'concurrency': [] }, done ); // $ExpectError
|
|
107
|
-
parallel( files, { 'concurrency': {} }, done ); // $ExpectError
|
|
108
|
-
parallel( files, { 'concurrency': ( x: number ): number => x }, done ); // $ExpectError
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// The compiler throws an error if the function is provided a `ordered` option which is not a boolean...
|
|
112
|
-
{
|
|
113
|
-
const files = [ './a.js', './b.js ' ];
|
|
114
|
-
parallel( files, { 'ordered': 'abc' }, done ); // $ExpectError
|
|
115
|
-
parallel( files, { 'ordered': 123 }, done ); // $ExpectError
|
|
116
|
-
parallel( files, { 'ordered': null }, done ); // $ExpectError
|
|
117
|
-
parallel( files, { 'ordered': [] }, done ); // $ExpectError
|
|
118
|
-
parallel( files, { 'ordered': {} }, done ); // $ExpectError
|
|
119
|
-
parallel( files, { 'ordered': ( x: number ): number => x }, done ); // $ExpectError
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// The compiler throws an error if the function is provided a `uid` option which is not a number...
|
|
123
|
-
{
|
|
124
|
-
const files = [ './a.js', './b.js ' ];
|
|
125
|
-
parallel( files, { 'uid': 'abc' }, done ); // $ExpectError
|
|
126
|
-
parallel( files, { 'uid': false }, done ); // $ExpectError
|
|
127
|
-
parallel( files, { 'uid': true }, done ); // $ExpectError
|
|
128
|
-
parallel( files, { 'uid': null }, done ); // $ExpectError
|
|
129
|
-
parallel( files, { 'uid': [] }, done ); // $ExpectError
|
|
130
|
-
parallel( files, { 'uid': {} }, done ); // $ExpectError
|
|
131
|
-
parallel( files, { 'uid': ( x: number ): number => x }, done ); // $ExpectError
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// The compiler throws an error if the function is provided a `gid` option which is not a number...
|
|
135
|
-
{
|
|
136
|
-
const files = [ './a.js', './b.js ' ];
|
|
137
|
-
parallel( files, { 'gid': 'abc' }, done ); // $ExpectError
|
|
138
|
-
parallel( files, { 'gid': false }, done ); // $ExpectError
|
|
139
|
-
parallel( files, { 'gid': true }, done ); // $ExpectError
|
|
140
|
-
parallel( files, { 'gid': null }, done ); // $ExpectError
|
|
141
|
-
parallel( files, { 'gid': [] }, done ); // $ExpectError
|
|
142
|
-
parallel( files, { 'gid': {} }, done ); // $ExpectError
|
|
143
|
-
parallel( files, { 'gid': ( x: number ): number => x }, done ); // $ExpectError
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// The compiler throws an error if the function is provided a `maxBuffer` option which is not a number...
|
|
147
|
-
{
|
|
148
|
-
const files = [ './a.js', './b.js ' ];
|
|
149
|
-
parallel( files, { 'maxBuffer': 'abc' }, done ); // $ExpectError
|
|
150
|
-
parallel( files, { 'maxBuffer': false }, done ); // $ExpectError
|
|
151
|
-
parallel( files, { 'maxBuffer': true }, done ); // $ExpectError
|
|
152
|
-
parallel( files, { 'maxBuffer': null }, done ); // $ExpectError
|
|
153
|
-
parallel( files, { 'maxBuffer': [] }, done ); // $ExpectError
|
|
154
|
-
parallel( files, { 'maxBuffer': {} }, done ); // $ExpectError
|
|
155
|
-
parallel( files, { 'maxBuffer': ( x: number ): number => x }, done ); // $ExpectError
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// The compiler throws an error if the function is provided an invalid number of arguments...
|
|
159
|
-
{
|
|
160
|
-
const files = [ './a.js', './b.js ' ];
|
|
161
|
-
parallel(); // $ExpectError
|
|
162
|
-
parallel( files ); // $ExpectError
|
|
163
|
-
parallel( files, {}, done, 16 ); // $ExpectError
|
|
164
|
-
}
|
package/docs/usage.txt
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Usage: parallel [options] <script1> <script2> ...
|
|
3
|
-
|
|
4
|
-
Options:
|
|
5
|
-
|
|
6
|
-
-h, --help Print this message.
|
|
7
|
-
-V, --version Print the package version.
|
|
8
|
-
--cmd cmd Executable file/command.
|
|
9
|
-
--workers num Number of workers.
|
|
10
|
-
--concurrency num Number of scripts to run concurrently.
|
|
11
|
-
--ordered Preserve order of script output.
|
|
12
|
-
--uid uid Process user identity.
|
|
13
|
-
--gid gid Process group identity.
|
|
14
|
-
--maxbuffer size Max buffer size for stdout and stderr.
|
|
15
|
-
|