Struct shutdown::Shutdown[][src]

pub struct Shutdown { /* fields omitted */ }

Implementations

Create a new shutdown channel. In most cases the channel will be shutdown when CTRL-C is pressed and the process receives a SIGINT or SIGTERM signal. If needed you can also call shutdown_now manually to send a shutdown signal programmatically.

Examples

use shutdown::Shutdown;

let root = Shutdown::new().unwrap();

Create a new branch (child) that can be shutdown independent of the root (parent) channel. When the root (or parent to be more precise) is shutdown, the new branch (and any child branches) will also be shutdown.

Examples

use shutdown::Shutdown;

let root = Shutdown::new().unwrap();
let branch = root.branch();

// Shutdown a specific branch
branch.shutdown_now();

Create a new subscriber (sibling) that listens to an existing root (or previously created branch) for any shutdown signals.

Examples

use shutdown::Shutdown;

let root = Shutdown::new().unwrap();
let subscriber = root.subscribe();

Returns true is the channel received a shutdown signal.

Examples

use shutdown::Shutdown;

let root = Shutdown::new().unwrap();

while !root.is_shutdown() {
    // Do stuff...
}

Manually shutdown the root or a branch. This causes all connected subscribers and any child branches to be shutdown as well.

Examples

use shutdown::Shutdown;

let root = Shutdown::new().unwrap();
let branch = root.branch();

// Trigger a manual shutdown from code
root.shutdown_now();

Block until a shutdown signal is received. This can, for example, be used in a select to block to wait for a long running task while still being able to respond to a shutdown signal.

Examples

use shutdown::Shutdown;
use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() {
    let mut root = Shutdown::new().unwrap();

    tokio::select! {
        _ = root.recv() => (),
        _ = sleep(Duration::from_secs(300)) => (), // Long runnnig task
    }
}

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.