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
I am calling an async javascript function in rust/WASM. I would like to have the result in my rust function because I need to it to be synchronous.
Is there any ways to wait for the javascript function to resolve inside WASM ?
Here some code of what I am trying to do :
impl Transport for TransportJS {
fn exchange(&self) -> Result<Vec<u8>, Error> {
// Call the javscript function exchange
let promise = self.exchange();
log("Ok we have the promise");
// Wait for result of the async call
let result = ...
return Ok(result);
}
}
If necessary, I can provide a more complete example of the code.
Thanks
The text was updated successfully, but these errors were encountered:
No, it is not possible. The browser does not allow for blocking. This is a limitation in the browser, not in Rust or wasm-bindgen, so there's nothing we can do about it.
implTransportforTransportJS{fnexchange(&self){spawn_local(asyncmove{// Call the javscript function exchangelet promise = self.exchange();log("Ok we have the promise");// Wait for result of the async calllet result = ...});}}
Note that spawn_local does not block: it immediately returns () and then runs the Future in the background, it will not wait for the Future to finish.
Summary
I am calling an async javascript function in rust/WASM. I would like to have the result in my rust function because I need to it to be synchronous.
Is there any ways to wait for the javascript function to resolve inside WASM ?
Here some code of what I am trying to do :
If necessary, I can provide a more complete example of the code.
Thanks
The text was updated successfully, but these errors were encountered: