Skip to content

Commit

Permalink
Update graceful shutdown server doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Dec 11, 2023
1 parent c3f2427 commit 7f0765e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl ServerHandle {
pub fn stop_forcible(&self) {
self.tx_cmd.send(ServerCommand::StopForcible).ok();
}

/// Graceful stop server.
///
/// Call this function will stop server after all connections are closed,
Expand All @@ -55,11 +56,14 @@ impl ServerHandle {
/// let server = Server::new(acceptor);
/// let handle = server.handle();
///
/// // Gracefully shut down the server
/// handle.stop_graceful(None);
/// // Graceful shutdown the server
/// tokio::spawn(async move {
/// tokio::time::sleep(std::time::Duration::from_secs(60)).await;
/// handle.stop_graceful(None);
/// });
/// server.serve(router).await;
/// }
/// ```
///
pub fn stop_graceful(&self, timeout: impl Into<Option<Duration>>) {
self.tx_cmd.send(ServerCommand::StopGraceful(timeout.into())).ok();
}
Expand Down

0 comments on commit 7f0765e

Please sign in to comment.