#signal #SIGINT

signalbool

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

8 releases

new 0.2.2 Aug 8, 2018
0.2.1 Jan 17, 2018
0.2.0 Oct 31, 2017
0.1.4 Jun 1, 2017
0.1.3 May 30, 2017

#7 in #signal

Download history 14/week @ 2018-05-23 37/week @ 2018-05-30 1/week @ 2018-06-06 9/week @ 2018-06-13 9/week @ 2018-06-20 72/week @ 2018-06-27 47/week @ 2018-07-04 8/week @ 2018-07-11 23/week @ 2018-07-18 5/week @ 2018-07-25 37/week @ 2018-08-01 94/week @ 2018-08-08

118 downloads per month

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;
      }
    }
  }
}

lib.rs:

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;
      }
    }
  }
}
BSD-3-Clause license
  • No runtime deps

Reverse deps