TaskWithTimeout: After suspend, don't start timers for new tasks

This commit is contained in:
Scott Nonnenberg 2022-01-26 12:39:24 -08:00 committed by GitHub
parent 0cf28344a6
commit 5f34ece87c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 31 deletions

View file

@ -12,9 +12,11 @@ type TaskType = {
};
const tasks = new Set<TaskType>();
let shouldStartTimers = true;
export function suspendTasksWithTimeout(): void {
log.info(`TaskWithTimeout: suspending ${tasks.size} tasks`);
shouldStartTimers = false;
for (const task of tasks) {
task.suspend();
}
@ -22,6 +24,7 @@ export function suspendTasksWithTimeout(): void {
export function resumeTasksWithTimeout(): void {
log.info(`TaskWithTimeout: resuming ${tasks.size} tasks`);
shouldStartTimers = true;
for (const task of tasks) {
task.resume();
}
@ -75,7 +78,9 @@ export default function createTaskWithTimeout<T, Args extends Array<unknown>>(
};
tasks.add(entry);
startTimer();
if (shouldStartTimers) {
startTimer();
}
let result: unknown;