rust-windowing / winit

Window handling library in pure Rust

Home Page:https://docs.rs/winit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request]: Ability to make event_loop async to satisfy WGPU on WASM in Resumed Event

lexi-the-cute opened this issue · comments

I would like to request the ability to .await code within the event loop, such as inside the Resumed event. This'll allow initializing libraries such as WGPU which require async code to be ran on platforms without thread blocking such as WASM. Right now the only way to run async functions without blocking is to do it outside of the event loop and to keep asyncing everything up to the original function that the program starts at (with wasm_bindgen)

I'm trying to support 3 platforms. The platforms are Desktop, Android, and Web Browser. I have the first two platforms down which both wait for the Resumed event to be called before creating the window. This is the only thing preventing me from supporting the web browser

I see something called EventLoop::spawn. Still trying to figure out if I can somehow make that async

It has been previously discussed to add an async layer on top of winit for these purposes. Unofficially I've manifested this dream as async-winit, although I haven't had the energy to update it to winit v0.29.

I do plan to experiment with adding a platform-specific extension for an async event loop to Web in Winit.

You should consider handling async stuff out of band, e.g. use wasm_bindgen_futures::spawn_local() and send a user event when you are done if you still want to handle the result inside the event loop.

I do plan to experiment with adding a platform-specific extension for an async event loop to Web in Winit.

You should consider handling async stuff out of band, e.g. use wasm_bindgen_futures::spawn_local() and send a user event when you are done if you still want to handle the result inside the event loop.

thanks! i ended up learning about mutexes and made a static mutex to handle this