chemicstry / wasm_thread

A rust `std::thread` replacement for wasm32 target
Apache License 2.0
123 stars 16 forks source link

Transferring `transferable`s to the new thread #8

Open felipellrocha opened 2 years ago

felipellrocha commented 2 years ago

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

DouglasDwyer commented 2 years ago

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.

chemicstry commented 2 years ago

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.