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
Out of curiosity, why doesn't comlink automatically proxy callbacks out of the box or at least give an opt-in for that?
I have been able to achieve it in the following way…
function$<T>(w: Worker): Remote<T>{constremote=comlinkWrap<T>(w);returnnewProxy<Remote<T>>(remote,{get(target,prop,receiver){if(typeoftarget[prop]==='function'){returnnewProxy(target[prop],{apply(target,thisArg,argArray){// Proxy functions in the argument list as wellconstproxiedArgs=argArray.map(arg=>(typeofarg==='function' ? comlinkProxy(arg) : arg));returnReflect.apply(target,thisArg,proxiedArgs);},});}returnReflect.get(target,prop,receiver);},});}
Am I missing something important here?
The text was updated successfully, but these errors were encountered:
It does not do it automatically because every callback requires creating a new proxy that holds on to the proxied value, which is basically a memory leak.
If you want to automatically proxy callbacks, you can use transfer handlers. The example for in the README shows how to automatically proxy events and you can use the exact same technique for functions.
Yeah, then again... there is a strong chance for memory leaks with callbacks in general. I think I'm gonna in the end rather use some observed triggers in indexeddb (which is part of my whole setup for the project)
Out of curiosity, why doesn't
comlink
automatically proxy callbacks out of the box or at least give an opt-in for that?I have been able to achieve it in the following way…
Am I missing something important here?
The text was updated successfully, but these errors were encountered: