wasm_thread icon indicating copy to clipboard operation
wasm_thread copied to clipboard

Transferring `transferable`s to the new thread

Open felipellrocha opened this issue 2 years ago • 2 comments

I haven't been able to find a path that would allow me to do that

felipellrocha avatar Jun 17 '22 21:06 felipellrocha

Because the worker messaging API is utilized for thread initialization and termination, there isn't currently a way to send transferables to another thread. The wasm_thread crate would need to be modified to allow for user-generated messages to be posted across worker boundaries, and also allow for asynchronous entrypoints as mentioned in #6. This is possible, but in my view, not necessarily in keeping with the goal of the crate (which is to be a drop-in replacement for std::thread); such functionality would require adding WASM-specific details to the abstraction. It's totally up to the crate owner, of course, but I think it would probably be worth creating a separate crate with webworker-specific functionality (like async entrypoints and the postMessage API) to allow for these advanced worker use cases.

DouglasDwyer avatar Jun 18 '22 15:06 DouglasDwyer

Yes, implementing async entry points and message posting would deviate too far from std::thread API. If we were to implement such features, I think creating a separate crate is the best option. Most of the resuable code could be moved out of this crate and it would instead serve as an API bridge between std::thread and the new webworker-specific crate.

Unfortunatelly, I'm not currently working with wasm so I don't have any interest in implementing this, but I would be happy to accept PRs, help coordinate the effort, or just grant maintainer rights.

chemicstry avatar Jun 18 '22 20:06 chemicstry