Skip to content

Instantly share code, notes, and snippets.

@wperron
Last active July 13, 2021 18:17
Show Gist options
  • Save wperron/cbf2b5da4d3777d9a00ac281d3926a44 to your computer and use it in GitHub Desktop.
Save wperron/cbf2b5da4d3777d9a00ac281d3926a44 to your computer and use it in GitHub Desktop.
broadcast
import { delay } from "https://deno.land/std@0.101.0/async/delay.ts";
const send = new BroadcastChannel("a");
const recv = new BroadcastChannel("a");
addEventListener("fetch", (event) => {
event.respondWith(handler(event.request));
})
function handler(_req) {
send.postMessage(new Uint8Array(8));
return new Response("success");
}
recv.onmessage = async (_) => {
await delay(1000);
send.postMessage(new Uint8Array(8));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment