0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-30 09:08:00 -04:00
denoland-deno/cli/tests/workers/message_port.ts
Luca Casonato 6261c89e04
feat: transfer MessagePort between workers (#11076)
Add support for transferring `MessagePort`s between workers.
2021-06-22 16:30:16 +02:00

14 lines
300 B
TypeScript

const channel = new MessageChannel();
channel.port2.onmessage = (e) => {
channel.port2.postMessage(e.data === "2");
channel.port2.close();
};
self.postMessage("1", [channel.port1]);
self.onmessage = (e) => {
const port1 = e.ports[0];
port1.postMessage(e.data === "3");
port1.close();
};