use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
// Fire-and-forget
tokio::spawn(async {
sleep(Duration::from_millis(50)).await;
println!("background task done");
});
// Spawn and collect results
let handles: Vec<_> = (0..5).map(|i| {
tokio::spawn(async move {
sleep(Duration::from_millis(100)).await;
i * 10
})
}).collect();
for h in handles {
println!("got {}", h.await.unwrap());
}
sleep(Duration::from_millis(100)).await; // give the fire-and-forget time to finish
}
Create a free account and build your private vault. Share publicly whenever you want.