std-function
sync_channel: bounded queue
Set a maximum number of queued messages. A blocking send waits for capacity or disconnection. Capacity bounds message count, not the total bytes in owned messages. Expected stdout (not executed): 9 Common mistake: Sending more than the capacity from the only thread before receiving.
Formal Syntax & Structure
rust syntaxrust
mpsc::sync_channel::<T>(bound: usize) -> (SyncSender<T>, Receiver<T>)Working Example
Example Snippetrust
fn main() { use std::sync::mpsc; let (tx, rx) = mpsc::sync_channel(2); tx.send(4).unwrap(); tx.send(5).unwrap(); println!("{}", rx.recv().unwrap() + rx.recv().unwrap());}