use tokio_util::sync::CancellationToken; /// Install a ctrl-c handler that triggers the returned token. /// /// The first ctrl-c cancels gracefully; a second ctrl-c terminates the process. pub fn install_ctrl_c() -> CancellationToken { let token = CancellationToken::new(); let trigger = token.clone(); tokio::spawn(async move { if tokio::signal::ctrl_c().await.is_ok() { tracing::info!("ctrl-c received, shutting down"); trigger.cancel(); } if tokio::signal::ctrl_c().await.is_ok() { tracing::warn!("second ctrl-c — exiting now"); std::process::exit(130); } }); token }