use std::future::Future;
use cbsk_base::{anyhow, log};
use cbsk_base::tokio::task::JoinHandle;
pub mod signal;
pub async fn run<F>(runable: anyhow::Result<Vec<JoinHandle<()>>>, handles_exec: impl FnOnce(Vec<JoinHandle<()>>) -> F)
where F: Future<Output=Vec<JoinHandle<()>>> {
let handles = match runable {
Ok(handles) => { handles }
Err(e) => {
eprintln!("run error: {e:?}");
log::error!("run error: {e:?}");
return;
}
};
let handles = handles_exec(handles).await;
for handle in handles {
if let Err(e) = handle.await {
log::error!("handle error: {e:?}");
}
}
log::logger().flush();
}