[][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.


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

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

let (s, r) = unbounded();

thread::spawn(move || {

// 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))

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