RReverser / wasm-bindgen-rayon

An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
https://docs.rs/wasm-bindgen-rayon
Apache License 2.0
117 stars 8 forks source link

Problem using wasm-bindgen-rayon in wasm-bindgen-test #6

Open yuroitaki opened 3 months ago

yuroitaki commented 3 months ago

Related to https://github.com/GoogleChromeLabs/wasm-bindgen-rayon/issues/30, I tried to initalise thread pool in my wasm bindgen test with the following:

use wasm_bindgen_futures::{spawn_local, JsFuture};
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
async fn test() {
   spawn_local(JsFuture::from(init_thread_pool(8)).map(|_| ()));
   ...
}

and run the test with the following

wasm-pack test --firefox --release

but the webworkers don't seem to have been set up correctly (picture below) and my test just hang halfway — if i disable rayon in my code, the test will work

image
themighty1 commented 1 month ago

Since initThreadPool should be called from within the WebWorker, I'd expect this to work

wasm_bindgen_test_configure!(run_in_dedicated_worker);`

#[wasm_bindgen_test]
async fn test() {
   spawn_local(JsFuture::from(init_thread_pool(8)).map(|_| ()));
   ...
}

But even with the above change, my test hang. I worked around it by modifying the JS code produces by wasm-bindgen-test: