diff options
author | Thomas Whiteway <thomas.whiteway@gmail.com> | 2020-02-26 18:55:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-26 10:55:08 -0800 |
commit | 7207bf355e2b6418bb0d757859a5cdcdedf32530 (patch) | |
tree | c1e060455974cc2b46c2dfca6fcde5ce65e75177 /tokio/src/time | |
parent | a4c4ac254b36c5b78038d416e3b78912df293f8f (diff) |
time: avoid needing to `poll` DelayQueue after insertion (#2217)
If an entry is inserted in the queue before the next deadline, the
DelayQueue needs to update the Delay tracking the next time to poll.
If there is an existing Delay, reset that rather than replacing it as if
it's already been polled the task will be waiting for a notification
before it will poll again, and dropping the Delay means that that
notification will never be performed.
Diffstat (limited to 'tokio/src/time')
-rw-r--r-- | tokio/src/time/delay_queue.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tokio/src/time/delay_queue.rs b/tokio/src/time/delay_queue.rs index f6007d74..1790ada8 100644 --- a/tokio/src/time/delay_queue.rs +++ b/tokio/src/time/delay_queue.rs @@ -326,7 +326,12 @@ impl<T> DelayQueue<T> { }; if should_set_delay { - self.delay = Some(delay_until(self.start + Duration::from_millis(when))); + let delay_time = self.start + Duration::from_millis(when); + if let Some(ref mut delay) = &mut self.delay { + delay.reset(delay_time); + } else { + self.delay = Some(delay_until(delay_time)); + } } Key::new(key) |