pub fn new_lambda_channel<T: Send + 'static, U: Send + 'static, V: Clone + Send + 'static>(
input_capacity: Option<usize>,
output_capacity: Option<usize>,
shared_resource: V,
function: fn(&V, T) -> U,
) -> (Sender<T>, Receiver<U>, ThreadPool)Expand description
Creates two normal channels and connects them to a new ThreadPool to create a
multi-producer multi-consumer multi-threaded lambda-channel.
ยงExamples
use crossbeam_channel::RecvError;
use lambda_channel::new_lambda_channel;
fn fib(_: &Option<()>, n: i32) -> u64 {
if n <= 1 {
n as u64
} else {
fib(&None, n - 1) + fib(&None, n - 2)
}
}
let (s, r, _p) = new_lambda_channel(None, None, None, fib);
s.send(20).unwrap();
assert_eq!(r.recv(), Ok(6765));
s.send(10).unwrap();
drop(s);
assert_eq!(r.recv(), Ok(55));
assert_eq!(r.recv(), Err(RecvError));