Merge branch 'main' into henrymercer/no-cache-nightlies

This commit is contained in:
Henry Mercer 2023-01-20 17:35:04 +00:00 committed by GitHub
commit 54f4ea7a62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 33 deletions

31
lib/util.js generated
View file

@ -457,7 +457,9 @@ async function bundleDb(config, language, codeql, dbName) {
}
exports.bundleDb = bundleDb;
async function delay(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
// Immediately `unref` the timer such that it only prevents the process from exiting if the
// surrounding promise is being awaited.
return new Promise((resolve) => setTimeout(resolve, milliseconds).unref());
}
exports.delay = delay;
function isGoodVersion(versionSpec) {
@ -634,20 +636,19 @@ async function withTimeout(timeoutMs, promise, onTimeout) {
finished = true;
return result;
};
const timeout = new Promise((resolve) => {
setTimeout(() => {
if (!finished) {
// Workaround: While the promise racing below will allow the main code
// to continue, the process won't normally exit until the asynchronous
// task in the background has finished. We set this variable to force
// an exit at the end of our code when `checkForTimeout` is called.
hadTimeout = true;
onTimeout();
}
resolve(undefined);
}, timeoutMs);
});
return await Promise.race([mainTask(), timeout]);
const timeoutTask = async () => {
await delay(timeoutMs);
if (!finished) {
// Workaround: While the promise racing below will allow the main code
// to continue, the process won't normally exit until the asynchronous
// task in the background has finished. We set this variable to force
// an exit at the end of our code when `checkForTimeout` is called.
hadTimeout = true;
onTimeout();
}
return undefined;
};
return await Promise.race([mainTask(), timeoutTask()]);
}
exports.withTimeout = withTimeout;
/**

File diff suppressed because one or more lines are too long