rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.55k stars 876 forks source link

Web: queue `EventLoopProxy::send_event()` to microtask when triggered from outside the event loop #3728

Closed daxpedda closed 2 weeks ago

daxpedda commented 2 weeks ago

This also checks if its coming from a thread or not, in which case it doesn't queue it.

I also noticed some legacy code that deferred to ControlFlow::Poll when receiving events instead of waking up the event loop immediately, which I removed, so now events should come in faster regardless of PollStrategy.

Fixes #3715.

daxpedda commented 2 weeks ago

A few questions though: Why are we not using wasm_bindgen_futures internally ourselves?

We are in a few places. While it is true that wasm_bindgen_futures::spawn_local() actually uses queueMicrotask() internally, it also does way more then just that, which we don't need in this case.

And why does web_sys not expose queueMicrotask?

Just missing, I will make a PR.

madsmtm commented 2 weeks ago

Just missing, I will make a PR.

Don't sweat it, we do this sort of thing all the time in Winit, just curious.

daxpedda commented 2 weeks ago

Just missing, I will make a PR.

Don't sweat it, we do this sort of thing all the time in Winit, just curious.

Done in https://github.com/rustwasm/wasm-bindgen/pull/3981.