Crate brk_exit

Source
Expand description

§BRK Exit

GitHub Repo stars License Version Documentation Size Dependency status Discord Nostr Bluesky X

A simple crate that stops the program from exitting when blocking is activated until it is released. The purpose of that is to prevent exitting when a program is in the middle of saving data and thus prevent partial writes.

It’s built on top of ctrlc which handles Ctrl + C (SIGINT), stopping the program using the kill command (SIGTERM) and closing the terminal (SIGHUP) but it doesn’t support force kills (kill -9).

§Example

use std::{path::Path, thread::sleep, time::Duration};

use brk_exit::Exit;
use log::info;

fn main() {
    let exit = Exit::new();

    brk_logger::init(Some(Path::new(".log")));

    exit.block();

    let mut i = 0;
    while i < 21 {
        info!("i = {i}");
        sleep(Duration::from_secs(1));
        i += 1;
    }

    exit.release();

    let mut j = 0;
    while j < 10 {
        info!("j = {j}");
        sleep(Duration::from_secs(1));
        j += 1;
    }
}

Structs§

Exit