diff --git a/Cargo.toml b/Cargo.toml index a0e64df..2d87029 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[dev-dependencies] +jive = { git = "https://git.asonix.dog/safe-async/jive" } diff --git a/examples/mpsc.rs b/examples/mpsc.rs new file mode 100644 index 0000000..7ca273c --- /dev/null +++ b/examples/mpsc.rs @@ -0,0 +1,25 @@ +fn main() -> Result<(), Box> { + jive::block_on(async move { + let (tx, mut rx) = mpsc::channel(); + + for i in 0..10 { + let tx = tx.clone(); + jive::spawn(async move { + for j in 1..=10 { + let tx = tx.clone(); + jive::spawn(async move { + tx.send(i * 10 + j); + }); + } + }); + } + + drop(tx); + + while let Some(val) = rx.recv().await { + println!("Got {}", val); + } + })?; + + Ok(()) +}