-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comlink for Long Running Workers? #400
Comments
Hm, I'm not sure I follow. I always advocate for long-running workers, especially when Comlink is in use :D Regarding your callback + transferable question: That should work fine! // main.js
const api = Comlink.wrap(worker);
api.addStateChangeListener(Comlink.proxy(state => {
// ...
})); // worker.js
const cbs = [];
Comlink.expose({
addStateChangeListener(cb) {
cbs.push(cb);
}
});
// Transfer some ArrayBuffer every 16ms or something.
setInterval(() => {
for(const cb of cbs) {
const val = new Uint8Array([1,2,3]);
cb(Comlink.transfer(val, [val.buffer]));
}
}, 16); Does that make sense/help? |
Oh dude, please excuse me, for some reason when I incorrectly had this though, I though Comlink worked like greenlet. 😂 It was like one of those thoughts you have while walking, and it's been in the back of my head, but yeah that totally is wrong my bad haha!
Oh this is perfect! I really need to read the docs haha! 😂 Please excuse this issue, and I went ahead and opened this issue on WasmBoy, because I think it'd be a really cool use case for that 😄 Thanks again! |
No worries! Let me know if you run into any DX issues :) |
Yo @surma ! I'm following up from our chat at CDS with some of the ideas / thoughts I had for Comllink 😄
So just as a text explanation: what about especially performance-constrained applications? In this case, rather than chunking off one of commands, re-instantiating the worker every time, does it make more sense to one long-running worker? I know you suggested you could have a worker that uses callbacks to run a command and return a response everytime. But to give some context, in WasmBoy I explicitly need to ensure the data is a transferrable or else the transfer will not be fast enough to achieve the performance gains from workerizing, or even hit 60fps in some cases, which I know from @JamesLMilner 's amazing Web Worker Benchmark Article. Thus I am not entirely sure if that is how the callback system works?
Let me know what you think! 😄
The text was updated successfully, but these errors were encountered: