scuffle-signal

Crates.ioscuffle-signal
lib.rsscuffle-signal
version0.3.3
created_at2024-11-28 16:47:16.153904+00
updated_at2025-05-30 23:10:21.353233+00
descriptionErgonomic async signal handling.
homepage
repositoryhttps://github.com/scufflecloud/scuffle
max_upload_size
id1464770
size61,108
Developers (github:scufflecloud:developers)

documentation

https://docs.rs/scuffle-signal

README

scuffle-signal

[!WARNING]
This crate is under active development and may not be stable.

License: MIT OR Apache-2.0 docs.rs crates.io GitHub Actions: ci Codecov


A crate designed to provide a more user friendly interface to tokio::signal.

See the changelog for a full release history.

Feature flags

  • bootstrap — Enables scuffle-bootstrap support
  • docs — Enables changelog and documentation of feature flags

Why do we need this?

The tokio::signal module provides a way for us to wait for a signal to be received in a non-blocking way. This crate extends that with a more helpful interface allowing the ability to listen to multiple signals concurrently.

Example

use scuffle_signal::SignalHandler;
use tokio::signal::unix::SignalKind;

let mut handler = SignalHandler::new()
    .with_signal(SignalKind::interrupt())
    .with_signal(SignalKind::terminate());

// Wait for a signal to be received
let signal = handler.await;

// Handle the signal
let interrupt = SignalKind::interrupt();
let terminate = SignalKind::terminate();
match signal {
    interrupt => {
        // Handle SIGINT
        println!("received SIGINT");
    },
    terminate => {
        // Handle SIGTERM
        println!("received SIGTERM");
    },
}

License

This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: MIT OR Apache-2.0

Commit count: 1522

cargo fmt