Skip to content

Commit

Permalink
Add Server::serve_with_graceful_shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
cycraig authored and djc committed Jun 12, 2023
1 parent 0f8ccf8 commit 2ad9b9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mendes/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;
#[cfg(feature = "with-http-body")]
use std::error::Error as StdError;
use std::future::Future;
use std::net::SocketAddr;
use std::str;
use std::str::FromStr;
Expand Down Expand Up @@ -692,4 +693,9 @@ pub trait Server: Application {
type ServerError;

async fn serve(self, addr: &SocketAddr) -> Result<(), Self::ServerError>;
async fn serve_with_graceful_shutdown(
self,
addr: &SocketAddr,
signal: impl Future<Output = ()> + Send,
) -> Result<(), Self::ServerError>;
}
11 changes: 11 additions & 0 deletions mendes/src/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ where
.serve(ApplicationService::new(self))
.await
}

async fn serve_with_graceful_shutdown(
self,
addr: &SocketAddr,
signal: impl Future<Output = ()> + Send,
) -> Result<(), hyper::Error> {
hyper::Server::bind(addr)
.serve(ApplicationService::new(self))
.with_graceful_shutdown(signal)
.await
}
}

struct ApplicationService<A>(Arc<A>);
Expand Down

0 comments on commit 2ad9b9b

Please sign in to comment.