From 0bd72a359f3e9858baa6e79917317572b07d58b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 21:35:07 +0000 Subject: [PATCH 1/2] Initial plan From f2400f2143d2efafdf6e5c9e0316de4f6ed61ee5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 22:06:02 +0000 Subject: [PATCH 2/2] Fix scheduler cleanup and add stale-timeout-disabled queue cleanup test Agent-Logs-Url: https://github.com/nevware21/ts-async/sessions/76723270-b366-49bb-8ab1-5b1a77f316a3 Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com> --- lib/src/scheduler/taskScheduler.ts | 1 + lib/test/src/scheduler/scheduler.test.ts | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/src/scheduler/taskScheduler.ts b/lib/src/scheduler/taskScheduler.ts index c352a85..92fd028 100644 --- a/lib/src/scheduler/taskScheduler.ts +++ b/lib/src/scheduler/taskScheduler.ts @@ -325,6 +325,7 @@ export function createTaskScheduler(newPromise?: (executor: PromiseExecutor { _removeTask(_running, taskDetail); + _removeTask(_waiting, taskDetail); // If there was a timeout stop and clear taskDetail.t && taskDetail.t.cancel(); diff --git a/lib/test/src/scheduler/scheduler.test.ts b/lib/test/src/scheduler/scheduler.test.ts index eccf128..4d4a834 100644 --- a/lib/test/src/scheduler/scheduler.test.ts +++ b/lib/test/src/scheduler/scheduler.test.ts @@ -504,6 +504,24 @@ function batchTests(testKey: string, definition: TestDefinition) { ); }); + it("Disable Abort Stale timer clears settled tasks", (done) => { + let scheduler = createTaskScheduler(createAsyncPromise, "no-stale-" + testKey); + scheduler.setStaleTimeout(0); + + for (let lp = 0; lp < 100; lp++) { + scheduler.queue(() => lp); + } + + let finalTask = scheduler.queue(() => 100); + doAwait(finalTask, () => { + let schedulerState: any = (scheduler as any)["[[SchedulerState]]"]; + assert.equal(true, scheduler.idle, "The scheduler should be idle"); + assert.equal(getLength(schedulerState.r), 0, "Running tasks should be empty"); + assert.equal(getLength(schedulerState.w), 0, "Waiting tasks should be empty"); + done(); + }, failOnCall); + }); + it("Aborting Multiple Stale events", (done) => { let scheduler = createTaskScheduler(null as any, "AbortMultiple-" + testKey); scheduler.setStaleTimeout(100); @@ -731,4 +749,4 @@ function batchTests(testKey: string, definition: TestDefinition) { done(); }); }); -} \ No newline at end of file +}