Skip to content

Commit 6a817c1

Browse files
nikwenArGeoph
authored andcommitted
Update thread count calculation method in worker_threads example (WiseLibs#1268)
The Node.js documentation states that `os.cpus()` should not be used to calculate the amount of threads an app should launch because CPU information might be unavailable. In Node.js v19.4.0 and v18.14.0, `os.availableParallelism()` was added for that purpose.
1 parent 2320659 commit 6a817c1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/threads.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function drainQueue() {
5555
Spawn workers that try to drain the queue.
5656
*/
5757

58-
os.cpus().forEach(function spawn() {
58+
new Array(os.availableParallelism()).fill(null).forEach(function spawn() {
5959
const worker = new Worker('./worker.js');
6060

6161
let job = null; // Current item from the queue

0 commit comments

Comments
 (0)