azul_webrender_api::channel

Function unbounded_channel

Source
pub fn unbounded_channel<T>() -> (Sender<T>, Receiver<T>)
Expand description

Creates an MPMC channel that is a bit slower than the fast_channel but doesn’t have a limit on the number of messages held at a given time and therefore doesn’t block when sending. Creates a channel of unbounded capacity.

This channel has a growable buffer that can hold any number of messages at a time.

§Examples

use std::thread;
use crossbeam_channel::unbounded;

let (s, r) = unbounded();

// Computes the n-th Fibonacci number.
fn fib(n: i32) -> i32 {
    if n <= 1 {
        n
    } else {
        fib(n - 1) + fib(n - 2)
    }
}

// Spawn an asynchronous computation.
thread::spawn(move || s.send(fib(20)).unwrap());

// Print the result of the computation.
println!("{}", r.recv().unwrap());