#signal #sigint

signalbool

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

10 releases

0.2.4 Jul 9, 2020
0.2.3 Jun 28, 2019
0.2.2 Aug 8, 2018
0.2.1 Jan 17, 2018
0.1.3 May 30, 2017

#4 in #sigint

Download history 30/week @ 2020-11-07 14/week @ 2020-11-14 31/week @ 2020-11-21 25/week @ 2020-11-28 26/week @ 2020-12-05 13/week @ 2020-12-12 9/week @ 2020-12-19 19/week @ 2020-12-26 29/week @ 2021-01-02 18/week @ 2021-01-09 22/week @ 2021-01-16 22/week @ 2021-01-23 21/week @ 2021-01-30 28/week @ 2021-02-06 31/week @ 2021-02-13 21/week @ 2021-02-20

111 downloads per month
Used in soapysdr

BSD-3-Clause

7KB
95 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

~0–295KB