]> zoso.dev Git - libnemo.git/commitdiff
Save pool object URL so it can be revoked later.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:57:40 +0000 (12:57 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:57:40 +0000 (12:57 -0800)
src/lib/pool.ts

index d64cd7d9b5c37e105fa8ab5e4b20198adb414a89..32c7c790057628934aeb1405fd7ce6c0fa3768c0 100644 (file)
@@ -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)