expression

Observe receiver shutdown from producer

A producer can stop unnecessary work once the consumer is gone or has closed admission. Closure is not an acknowledgement that previous messages were processed. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Treating receiver closure as confirmation of successful processing.

Formal Syntax & Structure

rust syntaxrust
tx.closed().await; tx.is_closed()

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let (tx, rx) = tokio::sync::mpsc::channel::<u8>(1);    drop(rx);    tx.closed().await;    println!("{}", tx.is_closed());}
Rust Reference