diff --git a/lib/node_modules/@stdlib/utils/parallel/lib/defaults.js b/lib/node_modules/@stdlib/utils/parallel/lib/defaults.js index 77c73864d66a..0727cfd5362e 100644 --- a/lib/node_modules/@stdlib/utils/parallel/lib/defaults.js +++ b/lib/node_modules/@stdlib/utils/parallel/lib/defaults.js @@ -21,6 +21,7 @@ // MODULES // var numCPUs = require( '@stdlib/os/num-cpus' ); +var max = require( '@stdlib/math/base/special/fast/max' ); // MAIN // @@ -36,12 +37,17 @@ var numCPUs = require( '@stdlib/os/num-cpus' ); * // returns {...} */ function defaults() { + var n; + + // Accommodate single-core systems by ensuring at least 1 worker and 1 concurrent script: + n = max( 1, numCPUs - 1 ); + return { // Number of workers: - 'workers': numCPUs - 1, + 'workers': n, // Number of scripts to execute concurrently: - 'concurrency': numCPUs - 1, + 'concurrency': n, // Executable file/command: 'cmd': 'node', diff --git a/lib/node_modules/@stdlib/utils/parallel/lib/main.js b/lib/node_modules/@stdlib/utils/parallel/lib/main.js index 0ea28d7ced30..4351f550584a 100644 --- a/lib/node_modules/@stdlib/utils/parallel/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parallel/lib/main.js @@ -94,11 +94,11 @@ function parallel() { if ( !isFunction( clbk ) ) { throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); } - // Prevent the number of concurrent scripts exceeding the number of actual scripts to run. + // Prevent the number of concurrent scripts exceeding the number of actual scripts to run: if ( opts.concurrency > files.length ) { - opts.concurrency = files.length; + opts.concurrency = files.length || 1; } - // Prevent the number of workers exceeding the number of concurrent scripts (excess capacity), as some workers would never be allocated scripts to run and always be idle. + // Prevent the number of workers exceeding the number of concurrent scripts (excess capacity), as some workers would never be allocated scripts to run and always be idle: if ( opts.workers > opts.concurrency ) { opts.workers = opts.concurrency; } diff --git a/lib/node_modules/@stdlib/utils/parallel/test/test.main.js b/lib/node_modules/@stdlib/utils/parallel/test/test.main.js index 195d871e9def..f0d7f1425c03 100644 --- a/lib/node_modules/@stdlib/utils/parallel/test/test.main.js +++ b/lib/node_modules/@stdlib/utils/parallel/test/test.main.js @@ -305,6 +305,45 @@ tape( 'if the number of workers is greater than the concurrency, the function se } }); +tape( 'the function ensures at least one worker and a concurrency greater than or equal to unity', function test( t ) { + var parallel; + + parallel = proxyquire( './../lib/main.js', { + './node': exec, + './defaults.js': mockDefaults + }); + + parallel( files(), done ); + + function mockDefaults() { + return { + 'workers': 1, + 'concurrency': 1, + 'cmd': 'node', + 'ordered': false, + 'uid': null, + 'gid': null, + 'encoding': 'buffer', + 'maxBuffer': 200 * 1024 * 1024 + }; + } + + function done( error ) { + if ( error ) { + t.ok( false, error.message ); + } else { + t.ok( true, 'runs scripts successfully' ); + } + t.end(); + } + + function exec( files, opts, clbk ) { + t.strictEqual( opts.workers, 1, 'has at least 1 worker' ); + t.strictEqual( opts.concurrency, 1, 'has at least 1 concurrency' ); + clbk(); + } +}); + tape( 'the function runs scripts in parallel', function test( t ) { parallel( files(), done ); function done( error ) {