import { RpcProvider } from "worker-rpc"; import ChartDownloaderWorker from "./chartDownloader.worker?worker"; import { dbClient, getDbClient } from "../db/client"; import type { BindParams } from "sql.js"; const worker = new ChartDownloaderWorker(); const rpcProvider = new RpcProvider((message, transfer) => worker.postMessage(message, transfer), ); worker.onmessage = (e) => rpcProvider.dispatch(e.data); export const chartDownloaderEvent = new Event("startDownloadingCharts"); document.addEventListener("startDownloadingCharts", async () => { rpcProvider.registerRpcHandler("db", async ({ cmd, ...args }) => dbClient.rpc(cmd, args), ); rpcProvider.signal("start"); }); interface Args { s: string; p?: BindParams; }