macro_rules! run {
($($task:expr),+ $(,)?) => { ... };
}Expand description
Waits for a shutdown signal and then shuts down each task in order.
run! accepts one or more expressions that implement Task.
It returns an async block that, when .awaited:
- Calls
wait_for_shutdown_signaland blocks untilSIGINTorSIGTERMis received. - Iterates through each supplied task in declaration order, calling
Task::shutdownon each one. - Logs a tracing
infoevent for each step and anerrorevent for any task that returnsErr. - Returns
Ok::<(), modo::Error>(()).
ยงExample
use modo::runtime::Task;
use modo::Result;
struct Worker;
struct HttpServer;
impl Task for Worker {
async fn shutdown(self) -> Result<()> { Ok(()) }
}
impl Task for HttpServer {
async fn shutdown(self) -> Result<()> { Ok(()) }
}
#[tokio::main]
async fn main() -> Result<()> {
let worker = Worker;
let server = HttpServer;
modo::run!(worker, server).await
}