diff --git a/src/typegate/src/runtimes/patterns/worker_manager/pooling.ts b/src/typegate/src/runtimes/patterns/worker_manager/pooling.ts index 2b5898d47..844a3aed4 100644 --- a/src/typegate/src/runtimes/patterns/worker_manager/pooling.ts +++ b/src/typegate/src/runtimes/patterns/worker_manager/pooling.ts @@ -21,6 +21,7 @@ export type Consumer = (x: T) => void; export interface WaitQueue { push(consumer: Consumer, onCancel: () => void): void; shift(produce: () => W): boolean; + clear(): void; } export function createSimpleWaitQueue(): WaitQueue { @@ -37,6 +38,7 @@ export function createSimpleWaitQueue(): WaitQueue { } return false; }, + clear() {}, }; } @@ -76,6 +78,12 @@ export class WaitQueueWithTimeout implements WaitQueue { return false; } + clear() { + if (this.#timerId != null) { + clearTimeout(this.#timerId); + } + } + #timeoutHandler() { this.#cancelNextEntry(); this.#updateTimer(); @@ -101,9 +109,7 @@ export class WaitQueueWithTimeout implements WaitQueue { } [Symbol.dispose]() { - if (this.#timerId != null) { - clearTimeout(this.#timerId); - } + this.clear(); } } @@ -220,5 +226,6 @@ export class WorkerPool< ); this.#idleWorkers.forEach((worker) => worker.destroy()); this.#idleWorkers = []; + this.#waitQueue.clear(); } }