Expand description
§modo::runtime
Graceful shutdown runtime for modo applications.
Provides three composable building blocks for orderly process teardown:
Task— a trait for any service that can be shut down asynchronously.wait_for_shutdown_signal— async function that resolves onSIGINT(Ctrl+C) or, on Unix,SIGTERM.run!— macro that waits for a signal and then callsTask::shutdownon each supplied value in declaration order.
§Quick start
use modo::runtime::Task;
use modo::Result;
struct MyServer;
impl Task for MyServer {
async fn shutdown(self) -> Result<()> {
// perform graceful shutdown
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<()> {
let server = MyServer;
modo::run!(server).await
}§Using wait_for_shutdown_signal directly
use modo::runtime::wait_for_shutdown_signal;
#[tokio::main]
async fn main() {
wait_for_shutdown_signal().await;
println!("shutting down...");
}Traits§
- Task
- A service or resource that can be shut down gracefully.
Functions§
- wait_
for_ shutdown_ signal - Waits until the process receives a shutdown signal, then returns.