Skip to main content

run

Macro run 

Source
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:

  1. Calls wait_for_shutdown_signal and blocks until SIGINT or SIGTERM is received.
  2. Iterates through each supplied task in declaration order, calling Task::shutdown on each one.
  3. Logs a tracing info event for each step and an error event for any task that returns Err.
  4. 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
}