-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Describe the Bug
From the future_to_promise documentation:
If the
futureprovided panics then the returnedPromisewill not resolve. Instead it will be a leaked promise. This is an unfortunate limitation of wasm currently that’s hoped to be fixed one day!
This behavior is very undesirable, so I think it would be good to have a bug on file for it.
I'm also curious about what the exact wasm limitation is, and where I can follow plans to fix it.
Steps to Reproduce
Rust:
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::{future_to_promise, JsFuture};
#[wasm_bindgen]
pub fn mywasmfun() -> Promise {
future_to_promise(mywasmfun_impl())
}
async fn mywasmfun_impl() -> Result<JsValue, JsValue> {
panic!("Please catch this panic");
}JS:
import init, { mywasmfun } from './pkg/wasm_bindgen_async_panic.js';
async function run() {
await init();
try {
await mywasmfun();
} catch (e) {
console.log("Caught exception:", e);
}
}
run();Expected Behavior
Panics should be propagated upwards the "async stack" so that any awaits on the JS side can catch panics and don't keep waiting forever.
Actual Behavior
The panic never propagates, the await never completes.