mirror of
https://github.com/ente-io/ente.git
synced 2025-06-10 02:42:23 +00:00
Something in the previous arrangement was causing webpack to not pack worker/worker.ts as a web worker.
24 lines
720 B
TypeScript
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)),
|
|
);
|