use std::future::Future;
use trust_dns_resolver::proto::error::ProtoError;
use trust_dns_resolver::proto::Executor;
use trust_dns_resolver::name_server::{
GenericConnection, GenericConnectionProvider, RuntimeProvider, Spawn,
};
use crate::net::{AsyncStdTcpStream, AsyncStdUdpSocket};
use crate::time::AsyncStdTime;
#[derive(Clone, Copy)]
pub struct AsyncStdRuntime;
impl Executor for AsyncStdRuntime {
fn new() -> Self {
AsyncStdRuntime {}
}
fn block_on<F: Future>(&mut self, future: F) -> F::Output {
async_std::task::block_on(future)
}
}
#[derive(Clone, Copy)]
pub struct AsyncStdRuntimeHandle;
impl Spawn for AsyncStdRuntimeHandle {
fn spawn_bg<F>(&mut self, future: F)
where
F: Future<Output = Result<(), ProtoError>> + Send + 'static,
{
let _join = async_std::task::spawn(future);
}
}
impl RuntimeProvider for AsyncStdRuntime {
type Handle = AsyncStdRuntimeHandle;
type Tcp = AsyncStdTcpStream;
type Timer = AsyncStdTime;
type Udp = AsyncStdUdpSocket;
}
impl AsyncStdRuntime {
#[cfg(test)]
pub(crate) fn handle(&self) -> AsyncStdRuntimeHandle {
AsyncStdRuntimeHandle
}
}
pub type AsyncStdConnection = GenericConnection;
pub type AsyncStdConnectionProvider = GenericConnectionProvider<AsyncStdRuntime>;