port over all tests

This commit is contained in:
Benjamin Fry
2020-04-10 14:57:29 -07:00
parent 87efb45bf1
commit fd356c258b
11 changed files with 457 additions and 129 deletions

View File

@@ -0,0 +1,31 @@
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
use std::future::Future;
use std::time::Duration;
use async_trait::async_trait;
use trust_dns_resolver::proto::Time;
/// AsyncStd backed timer implementation
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"))
}
}