-
Notifications
You must be signed in to change notification settings - Fork 421
Description
How do you send MessagePort for a proxy to a 2nd Worker thread (so the 2nd worker call 1st Worker directly without having to go through main thread) ?
Main thread:
// create two workers
const aProxy = Comlink.wrap(new "aWorker.js));
const bProxy = Comlink.wrap(new "bWorker.js));
// sent MessagePort of 1st Worker to 2nd Worker
const aPort = await aProxy [ Comlink.createEndpoint ] ();
bProxy.setRemotePort(Comlink.transfer(aPort, [aPort]);
in bWorker:
// 2nd worker tries to call 1st Worker via MesagChannel
setRemotePort(aPort:MessagePort){
this.aProxy = (await Comlink.wrap(aPort));
// test here...
let result = await aProxy.aMethod(param1, param2, ...);
}
Exception thrown in bWorker is:
Uncaught (in promise) TypeError: Cannot read property 'apply' of undefined
It seems MessagePort wasn't property transferred or there is typecasting issue somewhere.