//main.ts
const worker = new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
});
worker.postMessage("Hello from main.ts");
//worker.ts
import { delay } from "https://deno.land/std@0.218.0/async/delay.ts";
// First await: waits for a second, then continues running the module.
await delay(1000);
// The message handler is only set after that 1s delay, so some of the messages
// that reached the worker during that second might have been fired when no
// handler was registered.
self.onmessage = (evt: MessageEvent) => {
console.log(evt.data);
};
Version: Deno 1.41.1
deployctl deploy --project=example-deploy-worker ./main.ts