1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use {
crate::platform::time::get_system_time,
core::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::Duration,
},
};
pub struct Delay {
expiration_timestamp: u64,
}
impl Delay {
pub fn new(duration: Duration) -> Self {
Self {
expiration_timestamp: get_system_time() + (duration.as_nanos() as u64),
}
}
}
impl Future for Delay {
type Output = ();
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
if get_system_time() < self.expiration_timestamp {
Poll::Pending
} else {
Poll::Ready(())
}
}
}