jive/examples/blocking.rs

23 lines
510 B
Rust
Raw Normal View History

2022-02-17 00:09:04 +00:00
use std::time::Duration;
fn main() -> Result<(), jive::task::JoinError> {
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
}