Hullo JS
Search…
interconnect
import { interconnect } from '@hullo/browser'
Inside main file:
1
const hub = new MessageChannel();
2
​
3
const worker: Worker = new Worker("...", { name: "other" });
4
worker.postMessage({
5
type: "interconnect",
6
hubIn: hub.port1,
7
hubOut: hub.port2
8
});
9
​
10
interconnect("main", hub.port1, hub.port2);
11
​
12
// and whenever you're ready
13
hub.port1.start();
14
hub.port2.start();
Copied!
Inside worker file:
1
addEventListener("message", event => {
2
if ("type" in event.data && event.data.type === "interconnect") {
3
interconnect("other", event.data.hubIn, event.data.hubOut);
4
}
5
});
Copied!
Last modified 1yr ago
Copy link