Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More generally useful doc example for .with_graceful shutdown() #2820

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions axum/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,22 @@ impl<M, S> Serve<M, S> {
///
/// ```
/// use axum::{Router, routing::get};
/// use std::future::IntoFuture;
/// use tokio::sync::oneshot;
///
/// # async {
/// let router = Router::new().route("/", get(|| async { "Hello, World!" }));
///
/// let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
/// axum::serve(listener, router)
/// .with_graceful_shutdown(shutdown_signal())
/// .await
/// .unwrap();
/// let (tx, rx) = oneshot::channel();
/// tokio::spawn(
/// axum::serve(listener, router)
/// .with_graceful_shutdown(async move { rx.await.unwrap_or(()) })
/// .into_future(),
/// );
/// // ...
/// tx.send(()).unwrap();
/// # };
///
/// async fn shutdown_signal() {
/// // ...
/// }
/// ```
pub fn with_graceful_shutdown<F>(self, signal: F) -> WithGracefulShutdown<M, S, F>
where
Expand Down Expand Up @@ -285,21 +287,22 @@ impl<M, S, F> WithGracefulShutdown<M, S, F> {
/// # Example
/// ```
/// use axum::{Router, routing::get};
/// use std::future::IntoFuture;
/// use tokio::sync::oneshot;
///
/// # async {
/// let router = Router::new().route("/", get(|| async { "Hello, World!" }));
///
/// let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
/// axum::serve(listener, router)
/// .with_graceful_shutdown(shutdown_signal())
/// .tcp_nodelay(true)
/// .await
/// .unwrap();
/// let (tx, rx) = oneshot::channel();
/// tokio::spawn(
/// axum::serve(listener, router)
/// .with_graceful_shutdown(async move { rx.await.unwrap_or(()) })
/// .into_future(),
/// );
/// // ...
/// tx.send(()).unwrap();
/// # };
///
/// async fn shutdown_signal() {
/// // ...
/// }
/// ```
pub fn tcp_nodelay(self, nodelay: bool) -> Self {
Self {
Expand Down