expression

Backpressure: reject excess queued work

A bounded queue lets an application define what happens when capacity runs out. This toy policy accepts the first two items and counts the rejected third. Real policies may reject, defer or coalesce work; never silently lose required data. Expected stdout (not executed): [1, 2] rejected=1 Common mistake: Assuming a queue bound itself defines what to do with excess work.

Formal Syntax & Structure

rust syntaxrust
try_send + explicit overload outcome

Working Example

Example Snippetrust
fn main() {    use std::sync::mpsc::{self, TrySendError};    let (tx, rx) = mpsc::sync_channel(2);    let mut rejected = 0;    for n in [1, 2, 3] { match tx.try_send(n) { Ok(()) => {}, Err(TrySendError::Full(_)) => rejected += 1, Err(TrySendError::Disconnected(_)) => panic!("closed") } }    drop(tx);    let accepted: Vec<_> = rx.into_iter().collect();    println!("{:?} rejected={rejected}", accepted);}
Rust Reference