mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
tokio-timer: fix DelayQueue bug when inserting shorter delay (#863)
Reset the delay of the queue in case an item that expires sooner than the last inserted is put into the queue.
This commit is contained in:
committed by
Carl Lerche
parent
fbad6297c5
commit
12546d1d9c
@@ -338,6 +338,16 @@ impl<T> DelayQueue<T> {
|
||||
|
||||
self.insert_idx(when, key);
|
||||
|
||||
// Set a new delay if the current's deadline is later than the one of the new item
|
||||
let should_set_delay = if let Some(ref delay) = self.delay {
|
||||
let current_exp = self.normalize_deadline(delay.deadline());
|
||||
current_exp > when
|
||||
} else { false };
|
||||
|
||||
if should_set_delay {
|
||||
self.delay = Some(self.handle.delay(self.start + Duration::from_millis(when)));
|
||||
}
|
||||
|
||||
Key::new(key)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user