Skip to content

Commit ea9a058

Browse files
authored
Update thread count calculation method in worker_threads example (#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 6f9d37c commit ea9a058

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)