Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
23 lines
740 B
Rust
23 lines
740 B
Rust
/// Cross-platform shutdown signal handling.
|
|
///
|
|
/// Provides a unified async future that resolves when the process should
|
|
/// shut down (SIGINT/SIGTERM on Unix, Ctrl+C/Ctrl+Break on Windows).
|
|
pub async fn shutdown_signal() {
|
|
#[cfg(unix)]
|
|
{
|
|
use tokio::signal::unix::{SignalKind, signal};
|
|
let mut sigint =
|
|
signal(SignalKind::interrupt()).expect("failed to create SIGINT signal handler");
|
|
let mut sigterm =
|
|
signal(SignalKind::terminate()).expect("failed to create SIGTERM signal handler");
|
|
tokio::select! {
|
|
_ = sigint.recv() => {},
|
|
_ = sigterm.recv() => {},
|
|
}
|
|
}
|
|
#[cfg(not(unix))]
|
|
{
|
|
tokio::signal::ctrl_c().await.ok();
|
|
}
|
|
}
|