-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
C-featureCategory: feature. This is adding a new feature.Category: feature. This is adding a new feature.
Description
Calling a default shutdown signal function prevents redundant code
I think putting the shutdown signal function as a default somewhere would make crates like axum look nicer when defining a shutdown signal, building servers would be easier, and developers wouldn't have to initialize it every time.
Proposal
One could easily make some sort of "shutdown signal" struct with a default new and a few customization options.
Here is the shutdown_signal function being referred to:
async fn shutdown_signal() {
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
};
#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};
#[cfg(not(unix))]
let terminate = std::future::pending::<()>();
tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}
println!("signal received, starting graceful shutdown");
}
Describe alternatives you've considered
I could possibly make my own wrapper? I tried to ask axum to do this as I use their crate, but they pointed out it was part of the hyper::server::Server struct
Metadata
Metadata
Assignees
Labels
C-featureCategory: feature. This is adding a new feature.Category: feature. This is adding a new feature.