#[cfg(feature = "http2")]
use send_wrapper::SendWrapper;
#[cfg(feature = "http2")]
pub(crate) struct ServiceSendWrapper<T>(SendWrapper<T>);
#[cfg(feature = "http2")]
impl<T> ServiceSendWrapper<T> {
pub(crate) fn new(inner: T) -> Self {
Self(SendWrapper::new(inner))
}
}
#[cfg(feature = "http2")]
impl<R, T> hyper::service::Service<R> for ServiceSendWrapper<T>
where
T: hyper::service::Service<R>,
{
type Response = T::Response;
type Error = T::Error;
type Future = SendWrapper<T::Future>;
fn call(&self, req: R) -> Self::Future {
SendWrapper::new(self.0.call(req))
}
}
#[cfg(feature = "http2")]
#[derive(Debug, Clone)]
pub(crate) struct CompioH2Executor;
#[cfg(feature = "http2")]
impl<F: std::future::Future<Output = ()> + Send + 'static> hyper::rt::Executor<F>
for CompioH2Executor
{
fn execute(&self, fut: F) {
compio::runtime::spawn(fut).detach();
}
}
#[cfg(feature = "http2")]
#[derive(Debug, Clone)]
pub(crate) struct CompioH2Timer;
#[cfg(feature = "http2")]
struct CompioSleep(SendWrapper<std::pin::Pin<Box<dyn std::future::Future<Output = ()>>>>);
#[cfg(feature = "http2")]
impl std::future::Future for CompioSleep {
type Output = ();
fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
self.0.as_mut().poll(cx)
}
}
#[cfg(feature = "http2")]
impl Unpin for CompioSleep {}
#[cfg(feature = "http2")]
impl hyper::rt::Sleep for CompioSleep {}
#[cfg(feature = "http2")]
impl hyper::rt::Timer for CompioH2Timer {
fn sleep(&self, duration: std::time::Duration) -> std::pin::Pin<Box<dyn hyper::rt::Sleep>> {
Box::pin(CompioSleep(SendWrapper::new(Box::pin(
compio::time::sleep(duration),
))))
}
fn sleep_until(&self, deadline: std::time::Instant) -> std::pin::Pin<Box<dyn hyper::rt::Sleep>> {
Box::pin(CompioSleep(SendWrapper::new(Box::pin(
compio::time::sleep_until(deadline),
))))
}
}