From ef27e8f049fb342749e89d32e80ed1624ab78cd9 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 12:57:40 -0800 Subject: [PATCH] Save pool object URL so it can be revoked later. --- src/lib/pool.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/pool.ts b/src/lib/pool.ts index d64cd7d..32c7c79 100644 --- a/src/lib/pool.ts +++ b/src/lib/pool.ts @@ -24,6 +24,7 @@ export class Pool { #resolve: Function = (value: unknown): void => { } #results: object[] = [] #threads: Thread[] = [] + #url: string get isDone (): boolean { for (const thread of this.#threads) { @@ -35,12 +36,12 @@ export class Pool { } constructor (fn: string) { - const url = URL.createObjectURL(new Blob([fn], { type: 'text/javascript' })) + this.#url = URL.createObjectURL(new Blob([fn], { type: 'text/javascript' })) for (let i = this.#cores; i > 0; i--) { const thread = { isBusy: false, //@ts-expect-error - worker: new Worker(url, { type: 'module', eval: true }) + worker: new Worker(this.#url, { type: 'module', eval: true }) } thread.worker.addEventListener('message', message => { const data = new TextDecoder().decode(message.data ?? message) -- 2.34.1