expression

gRPC: bound the application stream queue

A bounded queue prevents unlimited buffering of outbound messages at this application boundary. When it fills, choose an explicit policy: wait within a budget, reject work, or stop. It is not the same as HTTP/2 flow control and does not bound all transport buffers. Run in the accompanying Cargo project. Expected stdout (not executed): full: true received: 7 Common mistake: Using an unbounded queue because gRPC has transport flow control.

Formal Syntax & Structure

rust syntaxrust
mpsc::channel::<T>(capacity); sender.try_send(item)

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    use tokio::sync::mpsc;    let (tx, mut rx) = mpsc::channel(1);    tx.try_send(7_u64).unwrap();    let full = tx.try_send(8).unwrap_err();    println!("full: {}", matches!(full, mpsc::error::TrySendError::Full(8)));    println!("received: {}", rx.recv().await.unwrap());}
Rust Reference