1 use crate::transport::BoxFuture; 2 use std::{future::Future, sync::Arc}; 3 4 pub(crate) use hyper::rt::Executor; 5 6 #[derive(Copy, Clone)] 7 struct TokioExec; 8 9 impl<F> Executor<F> for TokioExec 10 where 11 F: Future + Send + 'static, 12 F::Output: Send + 'static, 13 { execute(&self, fut: F)14 fn execute(&self, fut: F) { 15 tokio::spawn(fut); 16 } 17 } 18 19 #[derive(Clone)] 20 pub(crate) struct SharedExec { 21 inner: Arc<dyn Executor<BoxFuture<'static, ()>> + Send + Sync + 'static>, 22 } 23 24 impl SharedExec { new<E>(exec: E) -> Self where E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static,25 pub(crate) fn new<E>(exec: E) -> Self 26 where 27 E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static, 28 { 29 Self { 30 inner: Arc::new(exec), 31 } 32 } 33 tokio() -> Self34 pub(crate) fn tokio() -> Self { 35 Self::new(TokioExec) 36 } 37 } 38 39 impl Executor<BoxFuture<'static, ()>> for SharedExec { execute(&self, fut: BoxFuture<'static, ()>)40 fn execute(&self, fut: BoxFuture<'static, ()>) { 41 self.inner.execute(fut) 42 } 43 } 44