Skip to content

Commit 60ddfb5

Browse files
cjihrigMoLow
authored andcommitted
chore: use os.availableParallelism()
This commit addresses an existing TODO in the code by moving to the new os.availableParallelism() instead of os.cpus().length. PR-URL: nodejs/node#45969 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> (cherry picked from commit fe5710effcb0b336853657e424da04407b0e49ad)
1 parent 9ff5db7 commit 60ddfb5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/internal/test_runner/test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const {
5656
} = require('#internal/validators')
5757
const { setTimeout } = require('#timers/promises')
5858
const { TIMEOUT_MAX } = require('#internal/timers')
59-
const { cpus } = require('os')
59+
const { cpus, availableParallelism } = require('os')
6060
const { bigint: hrtime } = process.hrtime
6161
const kCallbackAndPromisePresent = 'callbackAndPromisePresent'
6262
const kCancelledByParent = 'cancelledByParent'
@@ -205,7 +205,9 @@ class Test extends AsyncResource {
205205

206206
case 'boolean':
207207
if (concurrency) {
208-
this.concurrency = parent === null ? MathMax(cpus().length - 1, 1) : Infinity
208+
this.concurrency = parent === null
209+
? MathMax((typeof availableParallelism === 'undefined' ? cpus().length : availableParallelism()) - 1, 1)
210+
: Infinity
209211
} else {
210212
this.concurrency = 1
211213
}

0 commit comments

Comments
 (0)