Skip to content

Commit

Permalink
feat(server): Remove Send + Sync requirement for Body in with_gracefu…
Browse files Browse the repository at this point in the history
…l_shutdown

Also expand the single threaded example to use that.
  • Loading branch information
espindola authored and seanmonstar committed Oct 12, 2021
1 parent 7feab2f commit 1d553e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions examples/single_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + Send + Sync + 'static,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
E: NewSvcExec<IO, S::Future, S::Service, E, GracefulWatcher>,
Expand Down
6 changes: 3 additions & 3 deletions src/server/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + Send + Sync + 'static,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
F: Future<Output = ()>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
Expand Down Expand Up @@ -103,7 +103,7 @@ where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: HttpService<Body>,
E: ConnStreamExec<S::Future, S::ResBody>,
S::ResBody: Send + Sync + 'static,
S::ResBody: 'static,
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
{
type Future =
Expand All @@ -119,7 +119,7 @@ where
S: HttpService<Body>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: AsyncRead + AsyncWrite + Unpin,
S::ResBody: HttpBody + Send + 'static,
S::ResBody: HttpBody + 'static,
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<S::Future, S::ResBody>,
{
Expand Down

0 comments on commit 1d553e5

Please sign in to comment.