Add example with jive

This commit is contained in:
Aode (lion) 2022-02-17 13:53:09 -05:00
parent ac89bc9a91
commit 381211a51e
2 changed files with 28 additions and 0 deletions

View file

@ -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" }

25
examples/mpsc.rs Normal file
View file

@ -0,0 +1,25 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
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(())
}