will_exit

Crates.iowill_exit
lib.rswill_exit
version0.3.3
sourcesrc
created_at2022-01-03 03:34:30.127305
updated_at2023-05-12 02:05:07.665484
descriptionwork on program will exit
homepage
repositoryhttps://github.com/rise0chen/will_exit.git
max_upload_size
id506864
size15,062
Rise Chen (rise0chen)

documentation

README

will_exit

Usage

use core::time::Duration;
use std::thread;

fn main() {
    will_exit::init(2000).unwrap();
    std::panic::set_hook(Box::new(|info| {
        println!("{}", info);
        will_exit::exit(-1);
    }));

    thread::spawn(|| {
        thread::sleep(Duration::from_secs(6));
        will_exit::exit();
    });
    loop {
        if will_exit::will_exit() {
            break;
        }
        thread::sleep(Duration::from_millis(100));
    }
    println!("exit");
}
Commit count: 8

cargo fmt