tonic/transport/channel/service/
executor.rs

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