🦀 Rust - Channels
Channels
Updated at 2024-01-04 06:26
mpsc stands for multiple producer, single consumer.
// handle.join().unwrap();
fn main() { let (tx, rx) = mpsc:: channel(); }
let val = String:: from(" hi"); tx.send( val). unwrap();
let received = rx.recv(). unwrap(); println!(" Got: {}", received); }
let tx1 = mpsc::Sender:: clone(& tx);
use std:: sync::Mutex;
fn main() {
let m = Mutex::new(5);
{
let mut num = m.lock().unwrap();
*num = 6; x
}
println!(" m = {:?}", m);
}
When the channel is closed, iteration ends.