1 use crate::transport::channel::BoxFuture;
2 use hyper_util::rt::TokioExecutor;
3 use std::{future::Future, sync::Arc};
4 
5 pub(crate) use hyper::rt::Executor;
6 
7 #[derive(Clone)]
8 pub(crate) struct SharedExec {
9     inner: Arc<dyn Executor<BoxFuture<'static, ()>> + Send + Sync + 'static>,
10 }
11 
12 impl SharedExec {
new<E>(exec: E) -> Self where E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static,13     pub(crate) fn new<E>(exec: E) -> Self
14     where
15         E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static,
16     {
17         Self {
18             inner: Arc::new(exec),
19         }
20     }
21 
tokio() -> Self22     pub(crate) fn tokio() -> Self {
23         Self::new(TokioExecutor::new())
24     }
25 }
26 
27 impl<F> Executor<F> for SharedExec
28 where
29     F: Future<Output = ()> + Send + 'static,
30 {
execute(&self, fut: F)31     fn execute(&self, fut: F) {
32         self.inner.execute(Box::pin(fut))
33     }
34 }
35