-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Futures created with wasm_bindgen_futures::spawn_local
don't get executed
#6
Comments
Could you be blocking browser's main thread event loop? In order for worker to spawn you either have to return from js->rust call or await on async function, so it allows browser event loop to continue. To be more clear: busy looping in wasm main thread freezes the browser event loop. This means that no DOM events, network fetches or worker spawning can proceed. The already spawned workers should work fine though, unless they try to communicate with the main thread. |
I think the problem here might be the |
It's a crossbeam channel. This is on a spawned thread, so it shouldn't impact the main thread no? Also, this code worked fine previously in the main thread. In addition, the documentation on |
I might not have explained it well, but what I said also applies to the worker event loop. At least I think so, I haven't used wasm for a while now, so don't remember all the quirks. The docs for |
I have modified it to this: wasm_thread::spawn(move || {
log::info!("1: spawn");
wasm_bindgen_futures::spawn_local(async move {
log::info!("2: message {:?}", &message);
while Ok(message) = channel_receiver.recv().await {
log::info!("3: am i here?");
download.asset().await;
}
})
}); I still get nothing (now a tokio channel) |
@felipellrocha, I am unable to reproduce your issue with the following code:
The code produces both log messages. As such, this looks like it may be an issue with the channel implementation or event loop rather than an incompatibility in |
This worked: rustwasm/wasm-bindgen#2945 Thanks for the help :D |
For the record, that is quite a hacky solution; I think it'd be better if |
Closing this and tracking async entrypoints in #10 |
I'm spinning a thread using
wasm_thread
. Inside of it, I'm running some async functions inside of awasm_bindgen_futures::spawn_local
as such:Problem is that neither the 3rd
log::info!()
nor thedownload.asset().await
get called.Any idea why?
The text was updated successfully, but these errors were encountered: