Skip to main content

modo/runtime/
mod.rs

1//! Graceful shutdown runtime for the modo framework.
2//!
3//! This module provides three building blocks for orderly application teardown:
4//!
5//! - [`Task`] — a trait for any service that can be shut down asynchronously.
6//! - [`wait_for_shutdown_signal`] — an async function that resolves when the process
7//!   receives `SIGINT` (Ctrl+C) or, on Unix, `SIGTERM`.
8//! - `run!` — a macro that waits for a shutdown signal and then calls
9//!   [`Task::shutdown`] on each supplied value in declaration order.
10//!
11//! # Examples
12//!
13//! ## Using the `run!` macro
14//!
15//! ```rust,no_run
16//! use modo::runtime::Task;
17//! use modo::Result;
18//!
19//! struct MyServer;
20//!
21//! impl Task for MyServer {
22//!     async fn shutdown(self) -> Result<()> {
23//!         // perform graceful shutdown
24//!         Ok(())
25//!     }
26//! }
27//!
28//! #[tokio::main]
29//! async fn main() -> Result<()> {
30//!     let server = MyServer;
31//!     modo::run!(server).await
32//! }
33//! ```
34//!
35//! ## Using `wait_for_shutdown_signal` directly
36//!
37//! ```rust,no_run
38//! use modo::runtime::wait_for_shutdown_signal;
39//!
40//! #[tokio::main]
41//! async fn main() {
42//!     wait_for_shutdown_signal().await;
43//!     println!("shutting down...");
44//! }
45//! ```
46
47mod run_macro;
48mod signal;
49mod task;
50
51pub use signal::wait_for_shutdown_signal;
52pub use task::Task;