Medium
Calling recv() after every mpsc Sender has been dropped
The spawned thread clones tx, then drops both the clone and the original; every Sender is gone before main calls rx.recv(). What does recv() return?
main.rs
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel::<i32>();
let handle = thread::spawn(move || {
let tx2 = tx.clone();
drop(tx2);
drop(tx);
// both the clone and the original sender are dropped here
});
handle.join().unwrap();
match rx.recv() {
Ok(val) => println!("got: {}", val),
Err(e) => println!("recv error: {:?}", e),
}
}33 of 53 in Rust