From: Chris Duncan Date: Tue, 3 Dec 2024 20:17:49 +0000 (-0800) Subject: Fix pool parsing of worker response to account for no data. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=088395916e5e28f9343c0cd4f770b54694212604;p=libnemo.git Fix pool parsing of worker response to account for no data. --- diff --git a/src/lib/pool.ts b/src/lib/pool.ts index 76daf0f..49da45d 100644 --- a/src/lib/pool.ts +++ b/src/lib/pool.ts @@ -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) })