pub fn init(exit_time: u16) -> Result<(), Error>Expand description
设置调用exit()后多少毫秒后退出程序
Examples found in repository?
examples/base.rs (line 5)
4fn main() {
5 will_exit::init(2000).unwrap();
6 std::panic::set_hook(Box::new(|info| {
7 println!("{}", info);
8 will_exit::exit(-1);
9 }));
10
11 thread::spawn(|| {
12 thread::sleep(Duration::from_secs(6));
13 will_exit::exit(0);
14 });
15 loop {
16 if will_exit::will_exit() {
17 break;
18 }
19 thread::sleep(Duration::from_millis(100));
20 }
21 println!("exit");
22}