-
Notifications
You must be signed in to change notification settings - Fork 909
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
Examples: The winit::EventLoop should not be run in wasm_bindgen_futures::spawn_local #1457
Comments
I had a similar problem to yours, in that I was trying to use fetch from web_sys inside of the winit event loop. Eventually I got around this by constructing wasm_bindgen's let resolve = Closure::once(move |resp: JsValue| {
console::log_1(&"resolved".into());
let resp: web_sys::Response = resp.dyn_into().unwrap();
let resolve = Closure::once(move |array: JsValue| {
let array = js_sys::Uint8Array::new(&array);
do_stuff_with_bytes(array.to_vec().into());
});
resp.array_buffer().unwrap().then(&resolve);
resolve.forget();
});
let reject = Closure::once(move |resp: JsValue| {
console::log_2(&"rejected".into(), &resp);
});
window.fetch_with_str(&url).then2(&resolve, &reject);
resolve.forget();
reject.forget(); |
Running the event loop inside an async function blocks new futures from being spawned in the examples using spawn_local. This change moves the event loop out of the async function and runs it directly in main. To still be able to initialize the wgpu-rs adapter and device asynchronously, we therefore need to introduce a custom event that is sent to the event loop once the wgpu-rs adapter and device have been created. Fixes #454
Running the event loop inside an async function blocks new futures from being spawned in the examples using spawn_local. This change moves the event loop out of the async function and runs it directly in main. To still be able to initialize the wgpu-rs adapter and device asynchronously, we therefore need to introduce a custom event that is sent to the event loop once the wgpu-rs adapter and device have been created. Fixes #454
492: Encode render targets into the render pass blob r=grovesNL a=kvark Fixes #454 Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
@kvark yeah, the wgpu examples should be ok now, so we can close this. We'll also track the upstream fix for winit in rust-windowing/winit#1714 |
Running the event loop inside of an async function in spawn_local appears to block new JS promises from being run if they are created in an event callback:
rustwasm/wasm-bindgen#2246
I am not sure exactly how to restructure the examples, but figured I would post this here in case anyone knows the right way to do this or comes across the same issue as I did.
The text was updated successfully, but these errors were encountered: