1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

feat(node/os): Add availableParallelism (#20745)

This commit is contained in:
Rui He 2023-09-30 22:21:06 +08:00 committed by Bartek Iwańczuk
parent e178ac6a9e
commit 554b7792b4
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 12 additions and 0 deletions

View file

@ -125,6 +125,9 @@ const platform = os.platform();
is.string(platform);
assert.ok(platform.length > 0);
const availableParallelism = os.availableParallelism();
assert.ok(availableParallelism === navigator.hardwareConcurrency);
const arch = os.arch();
is.string(arch);
assert.ok(arch.length > 0);

View file

@ -102,6 +102,9 @@ export function arch(): string {
return process.arch;
}
// deno-lint-ignore no-explicit-any
(availableParallelism as any)[Symbol.toPrimitive] = (): number =>
availableParallelism();
// deno-lint-ignore no-explicit-any
(arch as any)[Symbol.toPrimitive] = (): string => process.arch;
// deno-lint-ignore no-explicit-any
@ -354,10 +357,16 @@ export function userInfo(
};
}
/* Returns an estimate of the default amount of parallelism a program should use. */
export function availableParallelism(): number {
return navigator.hardwareConcurrency;
}
export const EOL = isWindows ? "\r\n" : "\n";
export const devNull = isWindows ? "\\\\.\\nul" : "/dev/null";
export default {
availableParallelism,
arch,
cpus,
endianness,