time: wake DelayQueue when removing last item (#6752)

This commit is contained in:
Adam Cigánek
2024-08-06 16:22:31 +02:00
committed by GitHub
parent ab53bf0c47
commit 1e798d26ed
2 changed files with 19 additions and 0 deletions
+6
View File
@@ -766,6 +766,12 @@ impl<T> DelayQueue<T> {
}
}
if self.slab.is_empty() {
if let Some(waker) = self.waker.take() {
waker.wake();
}
}
Expired {
key: Key::new(key.index),
data: data.inner,
+13
View File
@@ -880,6 +880,19 @@ async fn peek() {
assert!(queue.peek().is_none());
}
#[tokio::test(start_paused = true)]
async fn wake_after_remove_last() {
let mut queue = task::spawn(DelayQueue::new());
let key = queue.insert("foo", ms(1000));
assert_pending!(poll!(queue));
queue.remove(&key);
assert!(queue.is_woken());
assert!(assert_ready!(poll!(queue)).is_none());
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}