timer_kit/delay_impl/
smol.rs

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