Skip to main content

Module runtime

Module runtime 

Source
Expand description

Graceful shutdown runtime for the modo framework.

This module provides three building blocks for orderly application teardown:

  • Task — a trait for any service that can be shut down asynchronously.
  • wait_for_shutdown_signal — an async function that resolves when the process receives SIGINT (Ctrl+C) or, on Unix, SIGTERM.
  • run! — a macro that waits for a shutdown signal and then calls Task::shutdown on each supplied value in declaration order.

§Examples

§Using the run! macro

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.