From: Chris Duncan Date: Tue, 3 Dec 2024 20:57:40 +0000 (-0800) Subject: Save pool object URL so it can be revoked later. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=ef27e8f049fb342749e89d32e80ed1624ab78cd9;p=libnemo.git Save pool object URL so it can be revoked later. --- 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)