https://github.com/lilydjwg/rust-signalbool
A simple crate to catch signals and set a boolean flag for later use.
https://github.com/lilydjwg/rust-signalbool
rust-library signal-handler
Last synced: 4 months ago
JSON representation
A simple crate to catch signals and set a boolean flag for later use.
- Host: GitHub
- URL: https://github.com/lilydjwg/rust-signalbool
- Owner: lilydjwg
- License: bsd-3-clause
- Created: 2017-05-27T07:59:03.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T13:28:50.000Z (about 4 years ago)
- Last Synced: 2026-01-28T22:17:26.921Z (6 months ago)
- Topics: rust-library, signal-handler
- Language: Rust
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A simple crate to catch signals and set a boolean flag for later use.
This crate doesn't create threads behind the scene.
[](https://crates.io/crates/signalbool)
[](https://github.com/lilydjwg/rust-signalbool)
# Example
Here is a program that sleeps until it receives three `SIGINT` signals.
```rust
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;
}
}
}
}
```