A library for gracefully shutting down asynchronous applications
This may be useful when you want to allow all in-flight processing to complete before shutting down in order to maintain a consistent state.
Add this to your Cargo.toml:
toml
[dependencies]
shutdown-async = "0.1.0"
You can use the library like so:
```rust use shutdown_async::ShutdownController;
async fn main() { let shutdown = ShutdownController::new();
tokio::task::spawn({ let mut monitor = shutdown.subscribe(); async move { // Wait for something to happen tokio::select! { _ = monitor.recv() => { println!("shutdown initiated"); } _ = tokio::time::sleep(ONE_YEAR) => { println!("one year has passed!"); } } } });
shutdown.shutdown().await; }
static ONEYEAR: std::time::Duration = std::time::Duration::fromsecs(60 * 60 * 24 * 365); ```