diff --git a/src/common.rs b/src/common.rs index 9be677e18..199e0d37f 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1434,7 +1434,7 @@ pub fn using_public_server() -> bool { pub struct ThrottledInterval { interval: Interval, - last_tick: Instant, + next_tick: Instant, min_interval: Duration, } @@ -1443,7 +1443,7 @@ impl ThrottledInterval { let period = i.period(); ThrottledInterval { interval: i, - last_tick: Instant::now() - period * 2, + next_tick: Instant::now(), min_interval: Duration::from_secs_f64(period.as_secs_f64() * 0.9), } } @@ -1456,8 +1456,9 @@ impl ThrottledInterval { pub fn poll_tick(&mut self, cx: &mut std::task::Context<'_>) -> Poll { match self.interval.poll_tick(cx) { Poll::Ready(instant) => { - if self.last_tick.elapsed() >= self.min_interval { - self.last_tick = Instant::now(); + let now = Instant::now(); + if self.next_tick <= now { + self.next_tick = now + self.min_interval; Poll::Ready(instant) } else { // This call is required since tokio 1.27