From 1d553e52c6953ea3b039f5c3f89d35cb56e2436a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Tue, 12 Oct 2021 14:51:35 -0700 Subject: [PATCH] feat(server): Remove Send + Sync requirement for Body in with_graceful_shutdown Also expand the single threaded example to use that. --- examples/single_threaded.rs | 8 ++++++++ src/server/server.rs | 2 +- src/server/shutdown.rs | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/single_threaded.rs b/examples/single_threaded.rs index e8885cdb78..ba3e449ceb 100644 --- a/examples/single_threaded.rs +++ b/examples/single_threaded.rs @@ -2,6 +2,7 @@ use std::cell::Cell; use std::rc::Rc; +use tokio::sync::oneshot; use hyper::body::{Bytes, HttpBody}; use hyper::header::{HeaderMap, HeaderValue}; @@ -81,6 +82,13 @@ async fn run() { let server = Server::bind(&addr).executor(LocalExec).serve(make_service); + // Just shows that with_graceful_shutdown compiles with !Send, + // !Sync HttpBody. + let (_tx, rx) = oneshot::channel::<()>(); + let server = server.with_graceful_shutdown(async move { + rx.await.ok(); + }); + println!("Listening on http://{}", addr); // The server would block on current thread to await !Send futures. diff --git a/src/server/server.rs b/src/server/server.rs index 377f7cb617..0d559c579d 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -121,7 +121,7 @@ where IO: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: MakeServiceRef, S::Error: Into>, - B: HttpBody + Send + Sync + 'static, + B: HttpBody + 'static, B::Error: Into>, E: ConnStreamExec<>::Future, B>, E: NewSvcExec, diff --git a/src/server/shutdown.rs b/src/server/shutdown.rs index 8a2ecaf306..2277a40964 100644 --- a/src/server/shutdown.rs +++ b/src/server/shutdown.rs @@ -54,7 +54,7 @@ where IO: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: MakeServiceRef, S::Error: Into>, - B: HttpBody + Send + Sync + 'static, + B: HttpBody + 'static, B::Error: Into>, F: Future, E: ConnStreamExec<>::Future, B>, @@ -103,7 +103,7 @@ where I: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: HttpService, E: ConnStreamExec, - S::ResBody: Send + Sync + 'static, + S::ResBody: 'static, ::Error: Into>, { type Future = @@ -119,7 +119,7 @@ where S: HttpService, S::Error: Into>, I: AsyncRead + AsyncWrite + Unpin, - S::ResBody: HttpBody + Send + 'static, + S::ResBody: HttpBody + 'static, ::Error: Into>, E: ConnStreamExec, {