use std::time::Duration;
use tokio_task_supervisor::TaskSupervisor;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let supervisor = TaskSupervisor::new();
for id in 0..3 {
let _ = supervisor.spawn_with_token(move |_token| async move {
println!("task {id}: started");
tokio::time::sleep(Duration::from_secs((id + 1) as u64)).await;
println!("task {id}: finished after waiting");
});
}
println!("main: calling shutdown so all tasks complete");
supervisor.shutdown().await;
println!("main: all background tasks done");
}