Handling Ctrl-C gracefully
axum re-exports hyper's Server which provides the with_graceful_shutdown
method that is easily combined with tokio's signal::ctrl_c function
(available under the signal
feature flag):
axum::Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(async {
tokio::signal::ctrl_c().await.expect("failed to listen to ctrl-c");
})
.await?;