timer_kit/delay_impl/
tokio.rs

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