Skip to content

Commit 38103a7

Browse files
codedokodeisaacs
authored andcommitted
Use availableParallelism, handle empty os.cpus()
When /proc is not available and os.cpus() returns an empty list, callLimit() doesn't run any of the functions. Fix this and also update tap which was broken in newer node versions PR-URL: isaacs#11 Credit: @codedokode Close: isaacs#11 Reviewed-by: @isaacs
1 parent e500ec3 commit 38103a7

File tree

3 files changed

+3584
-2703
lines changed

3 files changed

+3584
-2703
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const defLimit = require('os').cpus().length
1+
const os = require('os')
2+
// availableParallelism available only since node v19, for older versions use cpus()
3+
// cpus() can return an empty list if /proc is not mounted, use 1 in this case
4+
const defLimit = 'availableParallelism' in os ? os.availableParallelism() : Math.max(1, os.cpus().length)
25
const callLimit = (queue, limit = defLimit) => new Promise((res, rej) => {
36
let active = 0
47
let current = 0

0 commit comments

Comments
 (0)