mpsc-full
cargo devel CI / cargo CI (push) Successful in 1m26s
Details
cargo devel CI / cargo CI (push) Successful in 1m26s
Details
This commit is contained in:
parent
2a2dc41446
commit
d804f5b2a6
|
@ -897,6 +897,13 @@ dependencies = [
|
|||
"anyhow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mpsc-full"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
|
|
|
@ -15,11 +15,13 @@ members = [
|
|||
"members/matchmatchmatch",
|
||||
"members/future_stream",
|
||||
"members/mpsc",
|
||||
"members/mpsc-full",
|
||||
]
|
||||
default-members = [
|
||||
".",
|
||||
"members/revsqrt",
|
||||
"members/mpsc",
|
||||
"members/mpsc-full",
|
||||
"members/criterion-demo",
|
||||
"members/shortc",
|
||||
"members/pest-demo",
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "mpsc-full"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
|
@ -0,0 +1,31 @@
|
|||
//! what happens when we send a lot of items to an mpsc?
|
||||
|
||||
use std::{
|
||||
sync::{mpsc, Barrier},
|
||||
thread,
|
||||
};
|
||||
|
||||
const NUMS: &[u8] = &[1, 3, 3, 7, 0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf];
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
|
||||
for n in NUMS {
|
||||
sender.send(n).unwrap();
|
||||
}
|
||||
drop(sender);
|
||||
|
||||
let mut collect = Vec::new();
|
||||
|
||||
while let Ok(n) = receiver.recv() {
|
||||
collect.push(*n);
|
||||
}
|
||||
|
||||
for i in NUMS {
|
||||
assert!(collect.contains(i))
|
||||
}
|
||||
|
||||
println!("it stores the values, even when the sender is dropped");
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue