DDRCompanion/lib/chartDownloader/client.ts

26 lines
740 B
TypeScript
Raw Permalink Normal View History

2024-05-16 04:37:23 +00:00
import { RpcProvider } from "worker-rpc";
import ChartDownloaderWorker from "./chartDownloader.worker?worker";
2024-05-16 06:02:44 +00:00
import { dbClient, getDbClient } from "../db/client";
import type { BindParams } from "sql.js";
2024-05-16 04:37:23 +00:00
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");
2024-05-16 06:02:44 +00:00
document.addEventListener("startDownloadingCharts", async () => {
rpcProvider.registerRpcHandler("db", async ({ cmd, ...args }) =>
dbClient.rpc(cmd, args),
);
rpcProvider.signal("start");
2024-05-16 04:37:23 +00:00
});
2024-05-16 06:02:44 +00:00
interface Args {
s: string;
p?: BindParams;
}