use crate::transport::BoxFuture; use std::{future::Future, sync::Arc}; pub(crate) use hyper::rt::Executor; #[derive(Copy, Clone)] struct TokioExec; impl Executor for TokioExec where F: Future + Send + 'static, F::Output: Send + 'static, { fn execute(&self, fut: F) { tokio::spawn(fut); } } #[derive(Clone)] pub(crate) struct SharedExec { inner: Arc> + Send + Sync + 'static>, } impl SharedExec { pub(crate) fn new(exec: E) -> Self where E: Executor> + Send + Sync + 'static, { Self { inner: Arc::new(exec), } } pub(crate) fn tokio() -> Self { Self::new(TokioExec) } } impl Executor> for SharedExec { fn execute(&self, fut: BoxFuture<'static, ()>) { self.inner.execute(fut) } }