Add blocking, time examples
This commit is contained in:
parent
930bf80b21
commit
5536aaf1c2
22
examples/blocking.rs
Normal file
22
examples/blocking.rs
Normal 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
22
examples/time.rs
Normal 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(())
|
||||
})?
|
||||
}
|
Loading…
Reference in a new issue