std-method
SyncSender::send: wait for queue capacity
A producer may block until capacity becomes available. The receiver must be able to run independently. A queued value is not proof of completed processing. Expected stdout (not executed): 12 Common mistake: Joining a blocked producer before draining its bounded queue.
Formal Syntax & Structure
rust syntaxrust
sender.send(value) -> Result<(), SendError<T>>Working Example
Example Snippetrust
fn main() { use std::{sync::mpsc, thread}; let (tx, rx) = mpsc::sync_channel(1); let worker = thread::spawn(move || { for n in [2, 4, 6] { tx.send(n).unwrap(); } }); let sum: i32 = rx.into_iter().sum(); worker.join().unwrap(); println!("{sum}");}