// Created on savesnippets.com ยท https://savesnippets.com/dPFy7dkhcmdL3P use std::sync::mpsc; use std::thread; use std::time::Duration; fn main() { let (tx, rx) = mpsc::channel::(); // Three producers โ€” clone tx for each for i in 0..3 { let tx = tx.clone(); thread::spawn(move || { for j in 0..3 { tx.send(format!("from {i}: msg {j}")).unwrap(); thread::sleep(Duration::from_millis(10)); } }); } drop(tx); // close the original โ€” receiver loop ends when all clones drop for msg in rx { // iterator form โ€” yields until channel closes println!("got: {msg}"); } println!("done"); }