move maxThreads outside of loop

This commit is contained in:
Robert Brignull 2020-08-17 12:46:55 +01:00
parent aaeb9751bb
commit 5eb3736850
3 changed files with 5 additions and 5 deletions

4
lib/util.js generated
View file

@ -329,12 +329,12 @@ exports.getMemoryFlag = getMemoryFlag;
function getThreadsFlag() {
let numThreads;
const numThreadsString = core.getInput("threads");
const maxThreads = os.cpus().length;
if (numThreadsString) {
numThreads = Number(numThreadsString);
if (Number.isNaN(numThreads)) {
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
}
const maxThreads = os.cpus().length;
if (numThreads > maxThreads) {
core.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
numThreads = maxThreads;
@ -347,7 +347,7 @@ function getThreadsFlag() {
}
else {
// Default to using all threads
numThreads = os.cpus().length;
numThreads = maxThreads;
}
return `--threads=${numThreads}`;
}

File diff suppressed because one or more lines are too long

View file

@ -385,12 +385,12 @@ export function getMemoryFlag(): string {
export function getThreadsFlag(): string {
let numThreads: number;
const numThreadsString = core.getInput("threads");
const maxThreads = os.cpus().length;
if (numThreadsString) {
numThreads = Number(numThreadsString);
if (Number.isNaN(numThreads)) {
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
}
const maxThreads = os.cpus().length;
if (numThreads > maxThreads) {
core.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
numThreads = maxThreads;
@ -402,7 +402,7 @@ export function getThreadsFlag(): string {
}
} else {
// Default to using all threads
numThreads = os.cpus().length;
numThreads = maxThreads;
}
return `--threads=${numThreads}`;
}