From c66f611037eb895701e2a559d3273b9fbb7d9251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Wed, 22 Jan 2025 16:37:36 +0800 Subject: [PATCH] windows: Improve foreground task dispatching on Windows (continued) (#23415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- crates/gpui/src/platform/windows/platform.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index bf1ccc699049ae8ebb03c08d065ddabe4ab886f1..53e67067175458c032e1b2fea051302dc2d24d14 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -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(); } }