| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 48e3ad3 commit b2facef
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,19 @@ The operating system-specific end-of-line marker. | |||
| 26 | 26 | * `\n` on POSIX | |
| 27 | 27 | * `\r\n` on Windows | |
| 28 | 28 | ||
| 29 | + ## `os.availableParallelism()` | ||
| 30 | + | ||
| 31 | + <!-- YAML | ||
| 32 | + added: REPLACEME | ||
| 33 | + --> | ||
| 34 | + | ||
| 35 | + * Returns: {integer} | ||
| 36 | + | ||
| 37 | + Returns an estimate of the default amount of parallelism a program should use. | ||
| 38 | + Always returns a value greater than zero. | ||
| 39 | + | ||
| 40 | + This function is a small wrapper about libuv's [`uv_available_parallelism()`][]. | ||
| 41 | + | ||
| 29 | 42 | ## `os.arch()` | |
| 30 | 43 | ||
| 31 | 44 | <!-- YAML | |
@@ -1338,3 +1351,4 @@ The following process scheduling constants are exported by | |||
| 1338 | 1351 | [`process.arch`]: process.md#processarch | |
| 1339 | 1352 | [`process.platform`]: process.md#processplatform | |
| 1340 | 1353 | [`uname(3)`]: https://linux.die.net/man/3/uname | |
| 1354 | + [`uv_available_parallelism()`]: https://docs.libuv.org/en/v1.x/misc.html#c.uv_available_parallelism | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ const { | |||
| 45 | 45 | const { validateInt32 } = require('internal/validators'); | |
| 46 | 46 | ||
| 47 | 47 | const { | |
| 48 | + getAvailableParallelism, | ||
| 48 | 49 | getCPUs, | |
| 49 | 50 | getFreeMem, | |
| 50 | 51 | getHomeDirectory: _getHomeDirectory, | |
@@ -100,6 +101,7 @@ const getOSVersion = () => version; | |||
| 100 | 101 | */ | |
| 101 | 102 | const getMachine = () => machine; | |
| 102 | 103 | ||
| 104 | + getAvailableParallelism[SymbolToPrimitive] = () => getAvailableParallelism(); | ||
| 103 | 105 | getFreeMem[SymbolToPrimitive] = () => getFreeMem(); | |
| 104 | 106 | getHostname[SymbolToPrimitive] = () => getHostname(); | |
| 105 | 107 | getOSVersion[SymbolToPrimitive] = () => getOSVersion(); | |
@@ -364,6 +366,7 @@ function userInfo(options) { | |||
| 364 | 366 | ||
| 365 | 367 | module.exports = { | |
| 366 | 368 | arch, | |
| 369 | + availableParallelism: getAvailableParallelism, | ||
| 367 | 370 | cpus, | |
| 368 | 371 | endianness, | |
| 369 | 372 | freemem: getFreeMem, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -380,6 +380,10 @@ static void GetPriority(const FunctionCallbackInfo<Value>& args) { | |||
| 380 | 380 | args.GetReturnValue().Set(priority); | |
| 381 | 381 | } | |
| 382 | 382 | ||
| 383 | + static void GetAvailableParallelism(const FunctionCallbackInfo<Value>& args) { | ||
| 384 | + unsigned int parallelism = uv_available_parallelism(); | ||
| 385 | + args.GetReturnValue().Set(parallelism); | ||
| 386 | + } | ||
| 383 | 387 | ||
| 384 | 388 | void Initialize(Local<Object> target, | |
| 385 | 389 | Local<Value> unused, | |
@@ -397,6 +401,8 @@ void Initialize(Local<Object> target, | |||
| 397 | 401 | SetMethod(context, target, "getUserInfo", GetUserInfo); | |
| 398 | 402 | SetMethod(context, target, "setPriority", SetPriority); | |
| 399 | 403 | SetMethod(context, target, "getPriority", GetPriority); | |
| 404 | + SetMethod( | ||
| 405 | + context, target, "getAvailableParallelism", GetAvailableParallelism); | ||
| 400 | 406 | SetMethod(context, target, "getOSInformation", GetOSInformation); | |
| 401 | 407 | target | |
| 402 | 408 | ->Set(context, | |
@@ -417,6 +423,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 417 | 423 | registry->Register(GetUserInfo); | |
| 418 | 424 | registry->Register(SetPriority); | |
| 419 | 425 | registry->Register(GetPriority); | |
| 426 | + registry->Register(GetAvailableParallelism); | ||
| 420 | 427 | registry->Register(GetOSInformation); | |
| 421 | 428 | } | |
| 422 | 429 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,6 +255,8 @@ if (!common.isIBMi) { | |||
| 255 | 255 | is.number(os.uptime(), 'uptime'); | |
| 256 | 256 | } | |
| 257 | 257 | ||
| 258 | + is.number(+os.availableParallelism, 'availableParallelism'); | ||
| 259 | + is.number(os.availableParallelism(), 'availableParallelism'); | ||
| 258 | 260 | is.number(+os.freemem, 'freemem'); | |
| 259 | 261 | is.number(os.freemem(), 'freemem'); | |
| 260 | 262 | ||
@@ -264,3 +266,5 @@ if (common.isWindows) { | |||
| 264 | 266 | } else { | |
| 265 | 267 | assert.strictEqual(devNull, '/dev/null'); | |
| 266 | 268 | } | |
| 269 | + | ||
| 270 | + assert.ok(os.availableParallelism() > 0); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments