Skip to content

Commit

Permalink
time: wake DelayQueue when removing last item (#6752)
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam authored Aug 6, 2024
1 parent ab53bf0 commit 1e798d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tokio-util/src/time/delay_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions tokio-util/tests/time_delay_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 1e798d2

Please sign in to comment.