jive/examples/time.rs

39 lines
1 KiB
Rust
Raw Permalink Normal View History

2022-02-17 00:09:04 +00:00
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2022-02-17 00:09:04 +00:00
jive::block_on(async {
println!("hewwo");
let handles = (0..10)
2022-02-17 00:09:04 +00:00
.map(|i| {
jive::spawn(async move {
let handles = (1..=10)
.map(|j| {
jive::spawn_local(async move {
jive::time::sleep(Duration::from_secs(2)).await;
println!("{} slept", i * 10 + j);
})
})
.collect::<Vec<_>>();
for handle in handles {
handle.await?;
}
2023-08-27 22:16:18 +00:00
println!("{i} joined");
Ok(()) as Result<_, jive::task::sync::JoinError>
2022-02-17 00:09:04 +00:00
})
})
.collect::<Vec<_>>();
for handle in handles {
handle.await??;
2022-02-17 00:09:04 +00:00
}
2023-08-27 22:16:18 +00:00
println!("all joined");
2022-02-17 00:09:04 +00:00
Ok(())
})
2022-02-17 00:09:04 +00:00
}