Skip to content

Commit

Permalink
Add serve_incoming_with_graceful_shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Lucio Franco <[email protected]>
  • Loading branch information
LucioFranco authored and seanmonstar committed May 19, 2020
1 parent 68e26af commit c8a5dbd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,35 @@ where
self.serve_incoming2(incoming)
}

/// dox
pub fn serve_incoming_with_graceful_shutdown<I>(
self,
incoming: I,
signal: impl Future<Output = ()> + Send + 'static,
) -> impl Future<Output = ()> + 'static
where
I: TryStream + Send + 'static,
I::Ok: AsyncRead + AsyncWrite + Send + 'static + Unpin,
I::Error: Into<Box<dyn StdError + Send + Sync>>,
{
let incoming = incoming.map_ok(crate::transport::LiftIo);
let service = into_service!(self.filter);
let pipeline = self.pipeline;

async move {
let srv =
HyperServer::builder(hyper::server::accept::from_stream(incoming.into_stream()))
.http1_pipeline_flush(pipeline)
.serve(service)
.with_graceful_shutdown(signal)
.await;

if let Err(err) = srv {
log::error!("server error: {}", err);
}
}
}

async fn serve_incoming2<I>(self, incoming: I)
where
I: TryStream + Send,
Expand Down

0 comments on commit c8a5dbd

Please sign in to comment.