Skip to content

Commit 4e01db4

Browse files
committed
Update graceful shutdown example on type as well.
1 parent 5703338 commit 4e01db4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

axum/src/serve.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,22 @@ impl<M, S, F> WithGracefulShutdown<M, S, F> {
287287
/// # Example
288288
/// ```
289289
/// use axum::{Router, routing::get};
290+
/// use std::{future::IntoFuture, sync::Arc};
291+
/// use tokio::sync::oneshot;
290292
///
291293
/// # async {
292294
/// let router = Router::new().route("/", get(|| async { "Hello, World!" }));
293295
///
294296
/// let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
295-
/// axum::serve(listener, router)
296-
/// .with_graceful_shutdown(shutdown_signal())
297-
/// .tcp_nodelay(true)
298-
/// .await
299-
/// .unwrap();
297+
/// let (tx, rx) = oneshot::channel();
298+
/// tokio::spawn(
299+
/// axum::serve(listener, router)
300+
/// .with_graceful_shutdown(async move { rx.await.unwrap_or(()) })
301+
/// .into_future(),
302+
/// );
303+
/// // ...
304+
/// tx.send(()).unwrap();
300305
/// # };
301-
///
302-
/// async fn shutdown_signal() {
303-
/// // ...
304-
/// }
305306
/// ```
306307
pub fn tcp_nodelay(self, nodelay: bool) -> Self {
307308
Self {

0 commit comments

Comments
 (0)