Hi @Detegr ,
After some years of independent development, the CtrlC2 I maintain has fully met my expectations.
Now I hope to contribute back to the CtrlC crate.
The main improvements of Ctrlc2 to Ctrlc are,
-
The return value of the function set_handler is a thread handle, which can be used to wait for its end.
-
The parameter passed into the function set_handler is a closure, which returns a boolean value, which is used to represent whether the user is willing to end the program.
fn main() {
let handle = ctrlc2::set_handler(move || {
println!(" ");
println!("Ctrl-C received, ready to exiting...");
true
})
.unwrap();
println!("Waiting for Ctrl-C...");
handle.join().unwrap();
println!("Got it! Exiting...");
}
- The AsyncCtrlC structure is implemented, which is a Future that users can use for any asynchronous runtime such as
tokio or async-std.
async fn async_main() {
let ctrlc = ctrlc2::AsyncCtrlC::new(move || {
println!("Ctrl-C received!");
true
})
.expect("cannot create Ctrl+C handler");
println!("Waiting for Ctrl-C...");
ctrlc.await.unwrap();
println!("Got it! Exiting...");
}
If you think Ctrlc2 is a good improvement, I'd be happy to submit a PR to merge it back into CtrlC.
Hi @Detegr ,
After some years of independent development, the CtrlC2 I maintain has fully met my expectations.
Now I hope to contribute back to the
CtrlCcrate.The main improvements of
Ctrlc2toCtrlcare,The return value of the function
set_handleris a thread handle, which can be used to wait for its end.The parameter passed into the function
set_handleris a closure, which returns a boolean value, which is used to represent whether the user is willing to end the program.tokioorasync-std.If you think Ctrlc2 is a good improvement, I'd be happy to submit a PR to merge it back into CtrlC.