Skip to content

Commit

Permalink
Add try_bind_with_graceful_shutdown (seanmonstar#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr authored Apr 14, 2020
1 parent ae02473 commit a4ece42
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ where
(addr, fut)
}

/// Create a server with graceful shutdown signal.
///
/// When the signal completes, the server will start the graceful shutdown
/// process.
pub fn try_bind_with_graceful_shutdown(
self,
addr: impl Into<SocketAddr> + 'static,
signal: impl Future<Output = ()> + Send + 'static,
) -> Result<(SocketAddr, impl Future<Output = ()> + 'static), crate::Error> {
let addr = addr.into();
let (addr, srv) = try_bind!(self, &addr).map_err(crate::Error::new)?;
let srv = srv.with_graceful_shutdown(signal).map(|result| {
if let Err(err) = result {
log::error!("server error: {}", err)
}
});

Ok((addr, srv))
}

/// Setup this `Server` with a specific stream of incoming connections.
///
/// This can be used for Unix Domain Sockets, or TLS, etc.
Expand Down

0 comments on commit a4ece42

Please sign in to comment.