comlink
comlink copied to clipboard
Expose main to worker, same remote-object-style
Could not find this in examples.
worker-rpc
allows the worker to request values from main in a similar manner, (await remote.func()
).
I understand you can pass callbacks using Comlink.proxy
, but in some cases (an apparent) direct duplex communication indicates the intent better than passing the ball back-and-forth where the main should has first call a function, then the worker must memoize the callback etc.
Is this kind of duplex communication also possible with Comlink? What would be an example?
Thanks!
I would really prefer to use comlink
(I have discovered this library after growing increasingly frustrated by the boilerplate incurred by worker-rpc
, especially getting the typings right). At the same time, the seeming absence of two-way communication is a major stumbling block for me.
It's possible. I made a minimal Example here. And there are some tests outlining the setup.
@MrMadClown it's nice! Thank you, I will experiment with this again. Do you think this example should be added to the main repo and explicitly outlined in the README? I expect it would be a moderately common question.