Closed
Description
Describe the Bug
I'm trying to use std::sync::mpsc
to synchronize between the js-world and the wasm-world. Unfortunately I always get the following panicks:
sync_channel_bg.js:215 panicked at 'condvar wait not supported', library/std/src/sys/wasm/../unsupported/condvar.rs:21:9
[...]
sync_channel_bg.js:215 panicked at 'cannot recursively acquire mutex', library/std/src/sys/wasm/../unsupported/mutex.rs:22:9
[...]
Steps to Reproduce
I created an example code at https://github.com/ineiti/sync-channel that shows the error. It is mostly the following code:
#[wasm_bindgen]
pub fn greet() -> Result<(), JsValue> {
utils::set_panic_hook();
let (s1, r1) = mpsc::sync_channel::<&str>(1);
let settimeout_callback = Closure::wrap(Box::new(move || {
log_1(&JsValue::from_str("settimeout_callback"));
match s1.send("done") {
Ok(_) => log_1(&JsValue::from_str("OK")),
Err(e) => log_2(&JsValue::from_str("Error: "),
&JsValue::from_str(e.to_string().as_str())),
}
log_1(&JsValue::from_str("settimeout_callback done"));
}) as Box<dyn Fn()>);
window().unwrap().set_timeout_with_callback_and_timeout_and_arguments_0(
settimeout_callback.as_ref().unchecked_ref(), 1000)?;
settimeout_callback.forget();
match r1.recv(){
Ok(s) => log_2(&JsValue::from_str("Got: "), &JsValue::from_str(s)),
Err(e) => log_2(&JsValue::from_str("Error: "), &JsValue::from_str(e.to_string().as_str())),
};
Ok(())
}
I'm quite new to rust/wasm, so I probably copy/pasted the wrong examples together. But I tried different versions of this, and it always failed with the sync-channel failures.
Expected Behavior
The code should wait on the r1.recv()
until the setTimeout
sends the data through.
Actual Behavior
sync_channel_bg.js:215 panicked at 'condvar wait not supported', library/std/src/sys/wasm/../unsupported/condvar.rs:21:9
[...]
sync_channel_bg.js:215 panicked at 'cannot recursively acquire mutex', library/std/src/sys/wasm/../unsupported/mutex.rs:22:9
[...]