0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

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

This commit is contained in:
Rui He 2023-09-30 22:21:06 +08:00 committed by GitHub
parent 9017e789df
commit 74e4c7f80f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,