wasm-mt
wasm-mt copied to clipboard
Compatibility with standard async
Can this be used as a general executor for futures? Or maybe to make rayon
work on different workers?
I have been trying to find a way to make my program work on wasm, but since it has heavy computations, it take a very long time to process without multi-threading (There are some encryption decryption on very large files). So I made my program using the asynchronous paradigm of rust to pipeline my process, and a little bit of parallel processing with rayon
(both of which work very well when compiled on windows). But when I compile it for Wasm, I rayon isn't able to launch its executor threads. So I was wondering if there was a way to make this executor work with rayon, or if I would have to re implement the functionality I need from rayon myself using this.
Can this be used as a general executor for futures?
Yes, based on wasm_mt::Thread
, you can implement custom executors for Rust futures (such as the toy executors in README and more practical wasm-mt-pool) in a fairly general manner (in my opinion). But, please note that, for any Rust futures involved here, their actual entity is a JavaScript Promise whose conversion is facilitated by wasm-bindgen.
After seeing this example in wasm-bindgen, I guess it's also possible to adapt wasm-mt-pool
to being used with rayon
.
So I was wondering if there was a way to make this executor work with rayon, or if I would have to re implement the functionality I need from rayon myself using this.
I would suggest, maybe, you put aside the (possibly laborious) rayon adaptation for the moment. Instead, as a first step, just try executing your parallel tasks with wasm-mt-pool
to see if it works as you expect.