windows: Improve foreground task dispatching on Windows (continued) (#23415)

Closes #22653 again

In PR #23283, I thought that every `runnable` dispatched to the main
thread would correspond to an `EVENT_DISPATCHED` message in the message
queue. However, after testing, some `runnable`s occasionally weren’t
executed.

This PR updated the code as follows:  
```rust
if let Ok(runnable) = self.main_receiver.try_recv() {    <-- before
for runnable in self.main_receiver.drain() {            <-- after
    runnable.run();
}
```

This ensures that runnables are handled more proactively on the main
thread, now we handle `runnable`s with a much higher priority.

A big thanks to @MolotovCherry and @ArthurBrussee for their testing
efforts!

Release Notes:

- N/A
This commit is contained in:
张小白 2025-01-22 16:37:36 +08:00 committed by GitHub
parent 2f1af2ab69
commit c66f611037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -167,7 +167,7 @@ impl WindowsPlatform {
#[inline]
fn run_foreground_task(&self) {
if let Ok(runnable) = self.main_receiver.try_recv() {
for runnable in self.main_receiver.drain() {
runnable.run();
}
}