toy_async_runtime/
features.rs1use std::future::Future;
4use std::pin::Pin;
5use std::task::{Context, Poll};
6use std::time::SystemTime;
7
8pub struct Sleep {
10 now: SystemTime,
12 waiting_ms: u128,
14}
15
16impl Sleep {
18 pub fn new(ms: u128) -> Self {
19 Sleep {
20 now: SystemTime::now(),
21 waiting_ms: ms,
22 }
23 }
24}
25
26impl Future for Sleep {
27 type Output = ();
28
29 fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
30 if self.now.elapsed().unwrap().as_millis() >= self.waiting_ms {
31 Poll::Ready(())
32 } else {
33 Poll::Pending
34 }
35 }
36}
37
38