Skip to content

Commit

Permalink
Work around os.cpus() returning an empty array on unsupported platforms
Browse files Browse the repository at this point in the history
`os.cpus()` can return empty arrays on platforms not officially supported by Node.js. Use 1 as a minimum.

See <nodejs/node#38190>.

Co-authored-by: Mark Wubben <mark@novemberborn.net>
  • Loading branch information
catink123 and novemberborn committed Aug 27, 2022
1 parent 02f626f commit 4b03662
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/api.js
Expand Up @@ -246,14 +246,16 @@ export default class Api extends Emittery {
}
}));

// Resolve the correct concurrency value.
let concurrency = Math.min(os.cpus().length, isCi ? 2 : Number.POSITIVE_INFINITY);
if (apiOptions.concurrency > 0) {
concurrency = apiOptions.concurrency;
}

// Resolve the correct concurrency value. Note that `os.cpus()` can return empty arrays on
// platforms not officially supported by Node.js. Use 1 as a minimum.
// See <https://github.com/nodejs/node/issues/38190>.
let concurrency = Math.max(1, os.cpus().length);
if (apiOptions.serial) {
concurrency = 1;
} else if (apiOptions.concurrency > 0) {
concurrency = apiOptions.concurrency;
} else if (isCi) {
concurrency = 2;
}

const deregisteredSharedWorkers = [];
Expand Down

0 comments on commit 4b03662

Please sign in to comment.