signalbool

Crates.iosignalbool
lib.rssignalbool
version0.2.5
sourcesrc
created_at2017-05-27 08:00:13.174169
updated_at2022-06-21 13:31:13.422537
descriptionA simple crate to catch signals and set a boolean flag for later use.
homepagehttps://github.com/lilydjwg/rust-signalbool
repositoryhttps://github.com/lilydjwg/rust-signalbool
max_upload_size
id16474
size11,466
Rust-publish (github:flatbuffers:rust-publish)

documentation

https://docs.rs/signalbool

README

A simple crate to catch signals and set a boolean flag for later use.

This crate doesn't create threads behind the scene.

Crates.io Version GitHub stars

Example

Here is a program that sleeps until it receives three SIGINT signals.

extern crate signalbool;
extern crate nix;

use nix::unistd::sleep;

fn main() {
  let mut sb = signalbool::SignalBool::new(
    &[signalbool::Signal::SIGINT], signalbool::Flag::Interrupt,
  ).unwrap();
  let mut count = 0;
    
  loop {
    sleep(10);
    if sb.caught() {
      println!("Caught SIGINT.");
      count += 1;
      sb.reset();
      if count == 3 {
        break;
      }
    }
  }
}
Commit count: 25

cargo fmt