5 unstable releases

0.3.0 Apr 21, 2025
0.2.2 Jan 8, 2022
0.2.1 Jan 31, 2021
0.2.0 Dec 21, 2020
0.1.0 Nov 22, 2020

#1016 in Unix APIs

Download history 2332/week @ 2025-01-13 2275/week @ 2025-01-20 2642/week @ 2025-01-27 3644/week @ 2025-02-03 2721/week @ 2025-02-10 3801/week @ 2025-02-17 3740/week @ 2025-02-24 4246/week @ 2025-03-03 4047/week @ 2025-03-10 6044/week @ 2025-03-17 5939/week @ 2025-03-24 8052/week @ 2025-03-31 9343/week @ 2025-04-07 4767/week @ 2025-04-14 4584/week @ 2025-04-21 2337/week @ 2025-04-28

21,877 downloads per month
Used in 20 crates (10 directly)

Apache-2.0/MIT

130KB
1.5K SLoC

A module for integrating signal handling with the async-std runtime.

This provides the Signals struct which acts as a Stream of signals.

Example

use std::io::Error;

use async_std::prelude::*;

use signal_hook::consts::signal::*;
use signal_hook_async_std::Signals;

async fn handle_signals(mut signals: Signals) {
    while let Some(signal) = signals.next().await {
        match signal {
            SIGHUP => {
                // Reload configuration
                // Reopen the log file
            }
            SIGTERM | SIGINT | SIGQUIT => {
                // Shutdown the system;
            },
            _ => unreachable!(),
        }
    }
}

#[async_std::main]
async fn main() -> Result<(), Error> {
    let signals = Signals::new(&[SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
    let handle = signals.handle();

    let signals_task = async_std::task::spawn(handle_signals(signals));

    // Execute your main program logic

    // Terminate the signal stream.
    handle.close();
    signals_task.await;

    Ok(())
}

Signal-hook-async-std

Travis Build Status

This is a async-std adapter crate for the signal-hook crate. See the documentation for further details.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~3–12MB
~157K SLoC