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
use std::future::Future;
use std::time::Duration;
use async_trait::async_trait;
use trust_dns_resolver::proto::Time;
#[derive(Clone, Copy)]
pub struct AsyncStdTime;
#[async_trait]
impl Time for AsyncStdTime {
async fn delay_for(duration: Duration) {
async_std::task::sleep(duration).await
}
async fn timeout<F: 'static + Future + Send>(
duration: Duration,
future: F,
) -> Result<F::Output, std::io::Error> {
async_std::future::timeout(duration, future)
.await
.map_err(move |_| std::io::Error::new(std::io::ErrorKind::TimedOut, "future timed out"))
}
}