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
First of all - great work! I've been trying to figure out for a while how comlink works under the hood but I eventually always gave up.
Comlink's wrap and expose aren't documented at all, and neither is proxy.
One thing I did notice however is that comlink seems to create an "anything goes" function as a Proxy target by default if no target is provided, which you just assert some types over. For some reason it works.
On the other hand, comctx requires shared code to be loaded both in the worker and the main thread according to the examples.
I feel this might be a problem for me as I have a pretty specific use case where the web worker itself has a lot of logic, and web-worker context specific code since I'm dealing with workers loading workers (emscripten with pthreads, transferables, close()). Splitting this to a chunk would mean I'd have to write isomorphic code with context checks and mocks if I'm not mistaken.
It's an issue to compile it to a shared chunk due to how my project is set up which would lead to code duplication. The worker and the main thread are 2 separate packages in the monorepo, since at the time vite didn't support multi-inputs in library mode, and the tsconfig lib rules are different.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First of all - great work! I've been trying to figure out for a while how comlink works under the hood but I eventually always gave up.
Comlink's
wrap
andexpose
aren't documented at all, and neither isproxy
.One thing I did notice however is that comlink seems to create an "anything goes" function as a
Proxy
target by default if notarget
is provided, which you just assert some types over. For some reason it works.On the other hand, comctx requires shared code to be loaded both in the worker and the main thread according to the examples.
I feel this might be a problem for me as I have a pretty specific use case where the web worker itself has a lot of logic, and web-worker context specific code since I'm dealing with workers loading workers (emscripten with pthreads, transferables,
close()
). Splitting this to a chunk would mean I'd have to write isomorphic code with context checks and mocks if I'm not mistaken.It's an issue to compile it to a shared chunk due to how my project is set up which would lead to code duplication. The worker and the main thread are 2 separate packages in the monorepo, since at the time vite didn't support multi-inputs in library mode, and the tsconfig lib rules are different.
So that was the intro 😅 what I'm getting at is:
transfer()
function.Btw, I'm also checking out https://github.com/daniel-nagy/transporter as an alternative to comlink.
Beta Was this translation helpful? Give feedback.
All reactions