You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having issues when calling two methods on the same proxied object and waiting on the results simultaneously. I have a minimal repro here (run yarn start and load the extension in the build folder) but here is the gist of it:
//background scriptimport*asComlinkfrom"comlink";import{createBackgroundEndpoint,isMessagePort}from"comlink-extension";import{browser}from"webextension-polyfill-ts";classBackgroundEndpoint{getSubProxy(){returnComlink.proxy({getB: ()=>{return"B";},});}getA(){return"A";}}browser.runtime.onConnect.addListener((port)=>{if(isMessagePort(port)){return;}Comlink.expose(newBackgroundEndpoint(),createBackgroundEndpoint(port));});//content scriptimport{createEndpoint}from"comlink-extension";import*asComlinkfrom"comlink";import{browser}from"webextension-polyfill-ts";constobj=Comlink.wrap(createEndpoint(browser.runtime.connect()));obj.getSubProxy().then((s)=>s.getB())// s.getB() never resolves and "B" is not logged.then(console.log);obj.getA().then(console.log);
The promise returned by s.getB() never resolves. The interesting thing is that changing the order of the promises (i.e. calling getA() before getSubProxy()) works fine. Also this is not a problem when using Comlink and web workers directly. Am I doing something obviously wrong here?
The text was updated successfully, but these errors were encountered:
Specifically, the port promise can resolve after a message has already been received and is lost. I'm not too familiar with Javascript internals but I assume it's an implementation detail whether the promise is resolved first or the message is processed.
I've opened #3 to make forward() sync and callers to use callbacks instead.
I'm having issues when calling two methods on the same proxied object and waiting on the results simultaneously. I have a minimal repro here (run
yarn start
and load the extension in thebuild
folder) but here is the gist of it:The promise returned by
s.getB()
never resolves. The interesting thing is that changing the order of the promises (i.e. callinggetA()
beforegetSubProxy()
) works fine. Also this is not a problem when using Comlink and web workers directly. Am I doing something obviously wrong here?The text was updated successfully, but these errors were encountered: