Add blocking, time examples

This commit is contained in:
Aode (lion) 2022-02-16 19:09:04 -05:00
parent 930bf80b21
commit 5536aaf1c2
2 changed files with 44 additions and 0 deletions

22
examples/blocking.rs Normal file
View file

@ -0,0 +1,22 @@
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(())
})?
}

22
examples/time.rs Normal file
View file

@ -0,0 +1,22 @@
use std::time::Duration;
fn main() -> Result<(), jive::task::JoinError> {
jive::block_on(async {
println!("hewwo");
let handles = (1..=50)
.map(|i| {
jive::spawn(async move {
jive::time::sleep(Duration::from_secs(2)).await;
println!("{} slept", i);
})
})
.collect::<Vec<_>>();
for handle in handles {
handle.await?;
}
Ok(())
})?
}