Last active
July 13, 2021 18:17
-
-
Save wperron/cbf2b5da4d3777d9a00ac281d3926a44 to your computer and use it in GitHub Desktop.
broadcast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { delay } from "https://deno.land/[email protected]/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