[][src]Function crossbeam_channel::never

pub fn never<T>() -> Receiver<T>

Creates a receiver that never delivers messages.

The channel is bounded with capacity of 0 and never gets disconnected.

Examples

Using a never channel to optionally add a timeout to select!:

use std::thread;
use std::time::{Duration, Instant};
use crossbeam_channel::{after, never, unbounded};

let (s, r) = unbounded();

thread::spawn(move || {
    thread::sleep(Duration::from_secs(1));
    s.send(1).unwrap();
});

// Suppose this duration can be a `Some` or a `None`.
let duration = Some(Duration::from_millis(100));

// Create a channel that times out after the specified duration.
let timeout = duration
    .map(|d| after(d))
    .unwrap_or(never());

select! {
    recv(r) -> msg => assert_eq!(msg, Ok(1)),
    recv(timeout) -> _ => println!("timed out"),
}