timer_kit/delay_impl/
futures_timer.rs

1use futures_timer::Delay;
2
3use std::time::Instant;
4
5impl crate::Delay for Delay {
6    type Value = ();
7
8    type Instant = Instant;
9
10    fn delay(duration: std::time::Duration) -> Self {
11        Delay::new(duration)
12    }
13
14    fn delay_until(deadline: Self::Instant) -> Self {
15        let now = Instant::now();
16        let duration = deadline.duration_since(now);
17        Delay::new(duration)
18    }
19
20    fn deadline(&self) -> Option<Self::Instant> {
21        None
22    }
23
24    fn poll_elapsed(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Value> {
25        std::future::Future::poll(self, cx)
26    }
27
28    fn reset(self: std::pin::Pin<&mut Self>, deadline: Self::Instant) {
29        let now = Instant::now();
30        let duration = deadline.duration_since(now);
31        futures_timer::Delay::reset(self.get_mut(), duration)
32    }
33}