Function crossbeam_channel::unbounded[][src]

pub fn unbounded<T>() -> (Sender<T>, Receiver<T>)

Creates a channel of unbounded capacity.

This type of channel can hold any number of messages (i.e. it has infinite capacity).

Examples

use std::thread;
use crossbeam_channel as channel;

let (s, r) = channel::unbounded();

// An expensive computation.
fn fib(n: i32) -> i32 {
    if n <= 1 {
        n
    } else {
        fib(n - 1) + fib(n - 2)
    }
}

// Spawn a thread doing an expensive computation.
thread::spawn(move || {
    s.send(fib(20));
});

// Let's see what's the result of the computation.
println!("{}", r.recv().unwrap());