diff --git a/examples/blocking.rs b/examples/blocking.rs new file mode 100644 index 0000000..ae441a3 --- /dev/null +++ b/examples/blocking.rs @@ -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::>(); + + for handle in handles { + handle.await?; + } + + Ok(()) + })? +} diff --git a/examples/time.rs b/examples/time.rs new file mode 100644 index 0000000..fcee5ca --- /dev/null +++ b/examples/time.rs @@ -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::>(); + + for handle in handles { + handle.await?; + } + + Ok(()) + })? +}