Skip to content

Commit

Permalink
fix: make timer cleanup explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Jan 29, 2025
1 parent 2bc7721 commit af729a7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/typegate/src/runtimes/patterns/worker_manager/pooling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Consumer<T> = (x: T) => void;
export interface WaitQueue<W> {
push(consumer: Consumer<W>, onCancel: () => void): void;
shift(produce: () => W): boolean;
clear(): void;
}

export function createSimpleWaitQueue<W>(): WaitQueue<W> {
Expand All @@ -37,6 +38,7 @@ export function createSimpleWaitQueue<W>(): WaitQueue<W> {
}
return false;
},
clear() {},

Check warning on line 41 in src/typegate/src/runtimes/patterns/worker_manager/pooling.ts

View check run for this annotation

Codecov / codecov/patch

src/typegate/src/runtimes/patterns/worker_manager/pooling.ts#L41

Added line #L41 was not covered by tests
};
}

Expand Down Expand Up @@ -76,6 +78,12 @@ export class WaitQueueWithTimeout<W> implements WaitQueue<W> {
return false;
}

clear() {
if (this.#timerId != null) {
clearTimeout(this.#timerId);
}
}

#timeoutHandler() {
this.#cancelNextEntry();
this.#updateTimer();
Expand All @@ -101,9 +109,7 @@ export class WaitQueueWithTimeout<W> implements WaitQueue<W> {
}

[Symbol.dispose]() {
if (this.#timerId != null) {
clearTimeout(this.#timerId);
}
this.clear();
}
}

Expand Down Expand Up @@ -220,5 +226,6 @@ export class WorkerPool<
);
this.#idleWorkers.forEach((worker) => worker.destroy());
this.#idleWorkers = [];
this.#waitQueue.clear();
}
}

0 comments on commit af729a7

Please sign in to comment.