Expand description
Unified graceful shutdown manager.
Provides a global CancellationToken that all modules can listen on
for coordinated graceful shutdown. One place handles SIGTERM/SIGINT,
all modules drain gracefully.
§Usage
use hyperi_rustlib::shutdown;
#[tokio::main]
async fn main() {
// Install the signal handler once at startup
let token = shutdown::install_signal_handler();
// Pass token to workers, or they can call shutdown::token() directly
tokio::spawn(async move {
loop {
tokio::select! {
_ = token.cancelled() => {
// drain and exit
break;
}
_ = do_work() => {}
}
}
});
}
async fn do_work() {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}Functions§
- install_
signal_ handler - Wait for SIGTERM or SIGINT, then trigger shutdown.
- is_
shutdown - Check if shutdown has been requested.
- token
- Get the global shutdown token.
- trigger
- Trigger shutdown programmatically.