DDRCompanion/lib/chartDownloader/client.ts
Michael Zhang dfbf923d04
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
download charts
2024-05-16 01:02:44 -05:00

25 lines
740 B
TypeScript

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;
}