From: Chris Duncan Date: Thu, 21 Nov 2024 04:53:33 +0000 (-0800) Subject: Fix premature Pool exit due to isDone return in for loop. Do not remove busy flag... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=fbbcc1ab98d98dca3d850a151c46da838d88a24f;p=libnemo.git Fix premature Pool exit due to isDone return in for loop. Do not remove busy flag from thread until it has reported its results. --- 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) {