From 9a3b8a8d6b7014e7ce642564487eda69baa5003e Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 16 Dec 2022 22:15:23 -0500 Subject: [PATCH] os: add availableParallelism() This commit exposes uv_available_parallelism() as an alternative to cpus().length. uv_available_parallelism() is inspired by Rust's available_parallelism(). --- doc/api/os.md | 11 +++++++++++ lib/os.js | 3 +++ src/node_os.cc | 7 +++++++ test/parallel/test-os.js | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/doc/api/os.md b/doc/api/os.md index e2e702dcea5ef49..c472801f3425dea 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -26,6 +26,17 @@ The operating system-specific end-of-line marker. * `\n` on POSIX * `\r\n` on Windows +## `os.availableParallelism()` + + + +* Returns: {integer} + +Returns an estimate of the default amount of parallelism a program should use. +Always returns a non-zero value. + ## `os.arch()`