jive/examples/blocking.rs

23 lines
529 B
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 move {
println!("hewwo");
let handles = (1..=50)
.map(|i| {
jive::spawn_blocking(move || {
std::thread::sleep(Duration::from_secs(2));
println!("{} blocked", i);
})
})
.collect::<Vec<_>>();
for handle in handles {
handle.await?;
}
Ok(())
})
2022-02-17 00:09:04 +00:00
}