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