]> zoso.dev Git - libnemo.git/commitdiff
Fix pool parsing of worker response to account for no data.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:17:49 +0000 (12:17 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:17:49 +0000 (12:17 -0800)
src/lib/pool.ts

index 76daf0fc0163ad29a9b7503e247e36dbd2677dd7..49da45dae5211c9f71dd79cbddea511d6a217f5f 100644 (file)
@@ -42,8 +42,9 @@ export class Pool {
                                //@ts-expect-error
                                worker: new Worker(url, { type: 'module', eval: true })
                        }
-                       thread.worker.addEventListener('message', (message) => {
-                               let result = JSON.parse(new TextDecoder().decode(message.data ?? message))
+                       thread.worker.addEventListener('message', message => {
+                               const data = new TextDecoder().decode(message.data ?? message)
+                               let result = JSON.parse(data || "[]")
                                if (!Array.isArray(result)) result = [result]
                                this.#report(thread, result)
                        })