Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 19, 2024
1 parent a7edeff commit c374e79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/api-calls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { Color } from "./Color";
import type { Palette } from "../stores/color-store";

// import using `?worker` suffix
import ViteWorker from "./heavy-computation.worker?worker";

// instantiate the worker
const tsWorker = new ViteWorker();

// send and receive messages from the worker
tsWorker.postMessage({ type: "test", content: "hellow" });

tsWorker.addEventListener("message", (msg: MessageEvent<string>) => {
console.log(msg.data); // how now, brown cow?
});

type Engine = "openai" | "google";
type SimplePal = { background: string; colors: string[] };
const palToString = (pal: Palette) => ({
Expand Down
17 changes: 17 additions & 0 deletions src/lib/heavy-computation.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type Command = { type: "load-data"; content: "" };

async function dispatch(cmd: Command) {
switch (cmd.type) {
case "load-data":
await loadData();
break;
}
}

self.onmessage = (event: MessageEvent<string>) => {
let response = "";
console.log("here", event.data);
self.postMessage(event.data);
};

export {}; // this is to make typescript happy

0 comments on commit c374e79

Please sign in to comment.