1use std::{future::Future, time::Duration};
2
3pub(crate) async fn async_task_with_spinner<F, T>(msg: &str, f: F) -> T
8where
9 F: Future<Output = T>,
10{
11 let pb = indicatif::ProgressBar::new_spinner();
12 let style = indicatif::ProgressStyle::default_bar();
13 pb.set_style(style.template("{spinner} {msg}").unwrap());
14 pb.set_message(msg.to_string());
15 pb.enable_steady_tick(Duration::from_millis(150));
16 let r = f.await;
17 pb.finish_and_clear();
18 r
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[tokio::test]
26 async fn test_spinner() {
27 async_task_with_spinner("Testing...", tokio::time::sleep(Duration::from_secs(5))).await
28 }
29}