use std::io;
use cbsk_base::{anyhow, log, tokio};
use cbsk_base::tokio::task::JoinHandle;
pub async fn ctrl_c() -> io::Result<()> {
tokio::signal::ctrl_c().await
}
pub async fn ctrl_c_stop_handles<T>(handles: &[JoinHandle<T>]) {
if let Err(e) = ctrl_c().await {
log::error!("monitor ctrl + c error : {e:?}");
return;
}
log::warn!("the program has received an end command and is about to exit the program");
handles.iter().for_each(|handle| { handle.abort(); });
log::logger().flush(); std::process::exit(0);}
pub async fn run(runable: anyhow::Result<Vec<JoinHandle<()>>>) {
super::run(runable, |handles| async {
ctrl_c_stop_handles(&handles).await;
handles
}).await;
}