Manav Rathi 004dd3bd0c
Rearrange to make webpack happy
Something in the previous arrangement was causing webpack to not pack
worker/worker.ts as a web worker.
2024-08-10 20:28:17 +05:30

24 lines
720 B
TypeScript

import { ComlinkWorker } from "@/base/worker/comlink-worker";
import type { CryptoWorker } from "./worker";
/**
* Cached instance of the {@link ComlinkWorker} that wraps our web worker.
*/
let _comlinkWorker: ComlinkWorker<typeof CryptoWorker> | undefined;
/**
* Lazily created, cached, instance of a CryptoWorker web worker.
*/
export const sharedCryptoWorker = async () =>
(_comlinkWorker ??= createComlinkCryptoWorker()).remote;
/**
* Create a new instance of a comlink worker that wraps a {@link CryptoWorker}
* web worker.
*/
export const createComlinkCryptoWorker = () =>
new ComlinkWorker<typeof CryptoWorker>(
"Crypto",
new Worker(new URL("worker.ts", import.meta.url)),
);