expression
Request/reply: separate acknowledgement
When processing completion matters, carry an explicit reply endpoint in the request. Receiving an acknowledgement communicates the application outcome, unlike successful enqueue. Bound outstanding requests and define error handling for real services. Expected stdout (not executed): 18 Common mistake: Counting successful enqueue as successful computation.
Formal Syntax & Structure
rust syntaxrust
request channel + response channelWorking Example
Example Snippetrust
fn main() { use std::{sync::mpsc, thread}; struct Request { number: u32, reply: mpsc::Sender<u32> } let (tx, rx) = mpsc::channel::<Request>(); let h = thread::spawn(move || { let req = rx.recv().unwrap(); req.reply.send(req.number * 2).unwrap(); }); let (reply, result) = mpsc::channel(); tx.send(Request { number: 9, reply }).unwrap(); println!("{}", result.recv().unwrap()); h.join().unwrap();}