From 16ecbafa7a28d4d788de4c1f432ac0d2baf4ed3f Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Mon, 9 Dec 2024 10:18:18 -0700 Subject: [PATCH] Skip spawning task for `background_executor.timer(Duration::ZERO)` (#21729) Release Notes: - N/A --- crates/gpui/src/executor.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index 3035892d7a17f23ee8db80ef4fdb3ad593e755ae..34132d72f841c20e3f97bf5cdf49200c0a56b568 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -328,6 +328,9 @@ impl BackgroundExecutor { /// Depending on other concurrent tasks the elapsed duration may be longer /// than requested. pub fn timer(&self, duration: Duration) -> Task<()> { + if duration.is_zero() { + return Task::ready(()); + } let (runnable, task) = async_task::spawn(async move {}, { let dispatcher = self.dispatcher.clone(); move |runnable| dispatcher.dispatch_after(duration, runnable)