feat(server): Remove Send + Sync requirement for Body in with_graceful_shutdown

Also expand the single threaded example to use that.
This commit is contained in:
Rafael Ávila de Espíndola
2021-10-12 14:51:35 -07:00
committed by Sean McArthur
parent 7feab2f3db
commit 1d553e52c6
3 changed files with 12 additions and 4 deletions

View File

@@ -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.