import { releaseProxy } from 'comlink' import { endpointSymbol } from 'vite-plugin-comlink/symbol' export interface ComlinkWorkerInstanceType { readonly [endpointSymbol]: Worker } export function destroyWorker(worker: ComlinkWorkerInstanceType) { if (!worker) return // https://github.com/mathe42/vite-plugin-comlink/pull/138 worker[endpointSymbol].terminate() worker[releaseProxy]() // fly to GC land, little proxy! } // Singleton sync worker - created on first use, reused thereafter let cachedSyncWorker: ComlinkWorker | null = null export function getSyncWorker() { if (!cachedSyncWorker) { cachedSyncWorker = new ComlinkWorker( new URL('./sync-worker.ts', import.meta.url), ) } return cachedSyncWorker }