Skip to content

Commit

Permalink
Use availableParallelism, handle empty os.cpus()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codedokode authored and isaacs committed Mar 31, 2023
1 parent e500ec3 commit 38103a7
Show file tree
Hide file tree
Showing 3 changed files with 3,584 additions and 2,703 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const defLimit = require('os').cpus().length
const os = require('os')
// availableParallelism available only since node v19, for older versions use cpus()
// cpus() can return an empty list if /proc is not mounted, use 1 in this case
const defLimit = 'availableParallelism' in os ? os.availableParallelism() : Math.max(1, os.cpus().length)
const callLimit = (queue, limit = defLimit) => new Promise((res, rej) => {
let active = 0
let current = 0
Expand Down
Loading

0 comments on commit 38103a7

Please sign in to comment.