async fn cancel_task() -> tokio::io::Result<()> {
let handle = tokio::spawn(async {
for i in 0..10 {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
println!("Ping! {}", i);
}
});
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
handle.abort();
match handle.await {
Ok(_) => Ok(()),
Err(e) if e.is_cancelled() => Ok(()),
Err(e) => Err(e),
}?;
Ok(())
}