std-type

RecvTimeoutError: expired wait versus end of stream

A wait may expire while future messages remain possible. Distinguish that case from a closed, drained channel so shutdown and deadline policies do not get mixed. Expected stdout (not executed): retry later finished Common mistake: Retrying disconnected channels indefinitely.

Formal Syntax & Structure

rust syntaxrust
RecvTimeoutError::Timeout; RecvTimeoutError::Disconnected

Working Example

Example Snippetrust
fn main() {    use std::{sync::mpsc::{self, RecvTimeoutError}, time::Duration};    let (tx, rx) = mpsc::channel::<()>();    fn label(e: RecvTimeoutError) -> &'static str { match e { RecvTimeoutError::Timeout => "retry later", RecvTimeoutError::Disconnected => "finished" } }    println!("{}", label(rx.recv_timeout(Duration::ZERO).unwrap_err()));    drop(tx);    println!("{}", label(rx.recv_timeout(Duration::ZERO).unwrap_err()));}
Rust Reference