Crate meltdown

Crate meltdown 

Source
Expand description

A lightweight service manager to help with graceful shutdown of asynchronous applications.

§Overview

Meltdown makes it easy to manage multiple long-running services and coordinate their graceful shutdown. A service can be any async task that needs to run continuously and can respond to a shutdown signal.

Meltdown is runtime-agnostic and works with any async runtime. It has minimal dependencies, only requiring futures_util and futures_channel for core async primitives.

§Creating Services

The simplest way to create a service is with an async function that takes a Token:

use meltdown::Token;

async fn my_service(token: Token) {
    println!("Service starting...");

    // Run until shutdown is triggered
    token.await;

    println!("Service shutting down...");
}

For more complex services, you can implement the Service trait directly.

§Managing Services

Use Meltdown to register and manage your services:

use meltdown::Meltdown;

let mut meltdown = Meltdown::new()
    .register(|_| async {
        // Completes immediately.
        1
    })
    .register(|token| async {
        // Waits for a shutdown trigger.
        token.await;
        2
    });

if let Some(id) = meltdown.next().await {
    println!("{id} stopped, shutting down");
    meltdown.trigger();
}

while let Some(id) = meltdown.next().await {
    println!("{id} stopped");
}

Modules§

catch_paniccatch-panic
Service for catching panics.
taggedtagged
Service for tagging other services with additional data.

Structs§

Meltdown
An asynchronous service manager.
Token
A token used to signal when to begin shutting down.

Traits§

Service
A long running service that supports graceful shutdown.