rs-basic/members/mpsc-full/src/main.rs

29 lines
572 B
Rust
Raw Normal View History

2024-03-04 12:17:55 +01:00
//! what happens when we send a lot of items to an mpsc?
2024-03-04 12:19:47 +01:00
use std::sync::mpsc;
2024-03-04 12:17:55 +01:00
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(())
}