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
Seems like it would be possible to build a wrapper for something like std::thread::spawn that, under the hood, sends the closure to another worker (possibly by boxing and maybe needs to turn it into a raw pointer)
pubfnspawn_thread<T,F>(f:F) -> JoinHandle<T>whereF:FnOnce() -> T + Send +'static,T:Send + 'static{// (std/crossbeam should work, maybe one_shot works too?)let(send, recv) = std::sync::mpsc::channel();let(out_send, out_recv) = std::sync::mpsc::channel();// create a worker with js_sys that:// - init the wasm module (produced by wasm-bindgen) inside the worker with the same (shared) WebAssembly.Memory// - recv and execute the closure// - send the result back// send the closure to the worker
send.send(f).unwrap()JoinHandle{recv: out_recv }}
(if this won't work please educate me why)
The text was updated successfully, but these errors were encountered:
I actually got a PoC working https://github.com/Pistonite/wasm-bindgen-spawn which I plan to use for my next project. For anyone looking for solutions, I also found https://github.com/chemicstry/wasm_thread which is a more elaborate implementation for more stuff in std::thread module. (I am curious why wasm_thread is not showing up in any google results)
We already got it working.
I meant sending the closure as a raw pointer instead of serializing/deserializing, using shared memory.
threads proposal has reached phase 4 - https://webassembly.org/features/
Seems like it would be possible to build a wrapper for something like
std::thread::spawn
that, under the hood, sends the closure to another worker (possibly by boxing and maybe needs to turn it into a raw pointer)(if this won't work please educate me why)
The text was updated successfully, but these errors were encountered: