#signal #SIGINT

signalbool

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

8 releases

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

#8 in #signal

Download history 104/week @ 2018-12-19 16/week @ 2018-12-26 17/week @ 2019-01-02 25/week @ 2019-01-09 16/week @ 2019-01-16 6/week @ 2019-01-23 19/week @ 2019-01-30 9/week @ 2019-02-06 4/week @ 2019-02-13 4/week @ 2019-02-20 23/week @ 2019-02-27 70/week @ 2019-03-06 6/week @ 2019-03-13 31/week @ 2019-03-20 27/week @ 2019-03-27

118 downloads per month
Used in 1 crate

BSD-3-Clause

7KB
98 lines

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

Dependencies

~774KB