Skip to content

Commit 1d553e5

Browse files
espindolaseanmonstar
authored andcommittedOct 12, 2021
feat(server): Remove Send + Sync requirement for Body in with_graceful_shutdown
Also expand the single threaded example to use that.
1 parent 7feab2f commit 1d553e5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
 

‎examples/single_threaded.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std::cell::Cell;
44
use std::rc::Rc;
5+
use tokio::sync::oneshot;
56

67
use hyper::body::{Bytes, HttpBody};
78
use hyper::header::{HeaderMap, HeaderValue};
@@ -81,6 +82,13 @@ async fn run() {
8182

8283
let server = Server::bind(&addr).executor(LocalExec).serve(make_service);
8384

85+
// Just shows that with_graceful_shutdown compiles with !Send,
86+
// !Sync HttpBody.
87+
let (_tx, rx) = oneshot::channel::<()>();
88+
let server = server.with_graceful_shutdown(async move {
89+
rx.await.ok();
90+
});
91+
8492
println!("Listening on http://{}", addr);
8593

8694
// The server would block on current thread to await !Send futures.

‎src/server/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ where
121121
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
122122
S: MakeServiceRef<IO, Body, ResBody = B>,
123123
S::Error: Into<Box<dyn StdError + Send + Sync>>,
124-
B: HttpBody + Send + Sync + 'static,
124+
B: HttpBody + 'static,
125125
B::Error: Into<Box<dyn StdError + Send + Sync>>,
126126
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
127127
E: NewSvcExec<IO, S::Future, S::Service, E, GracefulWatcher>,

‎src/server/shutdown.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
5555
S: MakeServiceRef<IO, Body, ResBody = B>,
5656
S::Error: Into<Box<dyn StdError + Send + Sync>>,
57-
B: HttpBody + Send + Sync + 'static,
57+
B: HttpBody + 'static,
5858
B::Error: Into<Box<dyn StdError + Send + Sync>>,
5959
F: Future<Output = ()>,
6060
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
@@ -103,7 +103,7 @@ where
103103
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
104104
S: HttpService<Body>,
105105
E: ConnStreamExec<S::Future, S::ResBody>,
106-
S::ResBody: Send + Sync + 'static,
106+
S::ResBody: 'static,
107107
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
108108
{
109109
type Future =
@@ -119,7 +119,7 @@ where
119119
S: HttpService<Body>,
120120
S::Error: Into<Box<dyn StdError + Send + Sync>>,
121121
I: AsyncRead + AsyncWrite + Unpin,
122-
S::ResBody: HttpBody + Send + 'static,
122+
S::ResBody: HttpBody + 'static,
123123
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
124124
E: ConnStreamExec<S::Future, S::ResBody>,
125125
{

0 commit comments

Comments
 (0)
Please sign in to comment.