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: #11
Credit: @codedokode
Close: #11
Reviewed-by: @isaacs

EDIT(@isaacs): formatted commit message and comment for line length,
added coverage ignore for node version-specific workaround
  • Loading branch information
codedokode authored and isaacs committed Mar 31, 2023
1 parent e500ec3 commit ad9ab47
Show file tree
Hide file tree
Showing 3 changed files with 3,590 additions and 2,703 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
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

/* istanbul ignore next - version-specific workaround */
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 ad9ab47

Please sign in to comment.