Skip spawning task for background_executor.timer(Duration::ZERO) (#21729)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2024-12-09 10:18:18 -07:00 committed by GitHub
parent e5f3a683f0
commit 16ecbafa7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)