From fbbcc1ab98d98dca3d850a151c46da838d88a24f Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 20 Nov 2024 20:53:33 -0800 Subject: [PATCH] Fix premature Pool exit due to isDone return in for loop. Do not remove busy flag from thread until it has reported its results. --- src/lib/pool.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/pool.ts b/src/lib/pool.ts index e4df098..b153485 100644 --- a/src/lib/pool.ts +++ b/src/lib/pool.ts @@ -28,8 +28,8 @@ export class Pool { if (thread.isBusy) { return false } - return true } + return true } constructor (url: string | URL) { @@ -39,7 +39,6 @@ export class Pool { worker: new Worker(new URL(url, import.meta.url), { type: 'module' }) } thread.worker.addEventListener('message', (message) => { - thread.isBusy = false this.#report(thread, message.data ?? message) }) this.#threads.push(thread) @@ -56,6 +55,7 @@ export class Pool { #report (thread: Thread, result: any) { this.#results.push(result) + thread.isBusy = false if (this.#queue.length > 0) { this.#assign(thread) } else if (this.isDone) { -- 2.34.1