From b2faceff0a521eb53a38e68c3535c86dab699b89 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(). PR-URL: https://github.com/nodejs/node/pull/45895 Reviewed-By: Moshe Atlow Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- doc/api/os.md | 14 ++++++++++++++ lib/os.js | 3 +++ src/node_os.cc | 7 +++++++ test/parallel/test-os.js | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/doc/api/os.md b/doc/api/os.md index 2f71d10090ca85..279ed1f18ddc0f 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -26,6 +26,19 @@ 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 value greater than zero. + +This function is a small wrapper about libuv's [`uv_available_parallelism()`][]. + ## `os.arch()`