]> zoso.dev Git - libnemo.git/commitdiff
Fix premature Pool exit due to isDone return in for loop. Do not remove busy flag...
authorChris Duncan <chris@zoso.dev>
Thu, 21 Nov 2024 04:53:33 +0000 (20:53 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 21 Nov 2024 04:53:33 +0000 (20:53 -0800)
src/lib/pool.ts

index e4df098b9273a01f49f5bb3b7538ad53e96fcba4..b153485639335e1c445bb26bcc428c015d85f12c 100644 (file)
@@ -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) {