Add example with jive
This commit is contained in:
parent
ac89bc9a91
commit
381211a51e
|
@ -6,3 +6,6 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
jive = { git = "https://git.asonix.dog/safe-async/jive" }
|
||||||
|
|
25
examples/mpsc.rs
Normal file
25
examples/mpsc.rs
Normal 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(())
|
||||||
|
}
|
Loading…
Reference in a new issue