-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add
navigator.hardwareConcurrency
Co-authored-by: Mestery <[email protected]> Co-authored-by: Voltrex <[email protected]>
- Loading branch information
1 parent
fdf8ecd
commit 81fc1cc
Showing
9 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const { | ||
ObjectDefineProperties, | ||
} = primordials; | ||
|
||
const { | ||
kEnumerableProperty, | ||
} = require('internal/util'); | ||
|
||
const { | ||
getAvailableParallelism, | ||
} = internalBinding('os'); | ||
|
||
class Navigator { | ||
/** | ||
* @return {number} | ||
*/ | ||
get hardwareConcurrency() { | ||
return getAvailableParallelism(); | ||
} | ||
} | ||
|
||
ObjectDefineProperties(Navigator.prototype, { | ||
hardwareConcurrency: kEnumerableProperty, | ||
}); | ||
|
||
module.exports = new Navigator(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
const is = { | ||
number: (value, key) => { | ||
assert(!Number.isNaN(value), `${key} should not be NaN`); | ||
assert.strictEqual(typeof value, 'number'); | ||
}, | ||
}; | ||
|
||
is.number(+navigator.hardwareConcurrency, 'hardwareConcurrency'); | ||
is.number(navigator.hardwareConcurrency, 'hardwareConcurrency'); | ||
assert.ok(navigator.hardwareConcurrency > 0); |