#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

#7 in #signal

Download history 20/week @ 2018-10-02 21/week @ 2018-10-09 87/week @ 2018-10-16 22/week @ 2018-10-23 12/week @ 2018-10-30 53/week @ 2018-11-06 28/week @ 2018-11-13 18/week @ 2018-11-20 16/week @ 2018-11-27 38/week @ 2018-12-04 11/week @ 2018-12-11 24/week @ 2018-12-18 104/week @ 2018-12-25

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

~778KB