Random stuff, testing things, and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
610 B

use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
let self_tx = tx.clone();
let consumer = thread::spawn(move || {
while let Ok(msg) = rx.recv() {
if msg == 0 {
println!("Quit");
break;
}
println!("Message: {}", msg);
}
});
let producer = thread::spawn(move || {
for i in 1..12 {
tx.send(i);
}
tx.send(0);
});
println!("Waiting producer...");
producer.join();
println!("Waiting consumer...");
consumer.join();
}