pub fn new_lambda_channel_with_input_and_output<T: Send + 'static, U: Send + 'static, V: Clone + Send + 'static>(
input_receiver: Receiver<T>,
output_sender: Sender<U>,
shared_resource: V,
function: fn(&V, T) -> U,
) -> ThreadPoolExpand description
Connects two existing channels to a new ThreadPool to
create a multi-producer multi-consumer multi-threaded lambda-channel.
While it is not required for the input channel of the lambda-channel to have the output
channel as a dependency, it may lead to undesired termination behaviors.
ยงExamples
use lambda_channel::new_lambda_channel_with_input_and_output;
use lambda_channel::channel::{new_channel, new_channel_with_dependency};
fn convert_units(c: &f64, u: f64) -> f64 {
c * u
}
fn approx_eq(v: f64, c: f64) -> bool {
if (v > (c + 0.000001)) || (v < (c - 0.000001)) {
return false;
}
true
}
let (s_km, r_km) = new_channel(None);
let (s_mile, r_mile_to_km) = new_channel_with_dependency(None, &s_km, &r_km);
let (s_nautical_mile, r_nautical_mile_to_km) = new_channel_with_dependency(None, &s_km, &r_km);
let _p_mile_to_km = new_lambda_channel_with_input_and_output(r_mile_to_km, s_km.clone(), 1.60934, convert_units);
let _p_nautical_mile_to_km = new_lambda_channel_with_input_and_output(r_nautical_mile_to_km, s_km, 1.852, convert_units);
s_mile.send(12.0).unwrap();
s_nautical_mile.send(2.0).unwrap();
let msg1 = r_km.recv().unwrap();
let msg2 = r_km.recv().unwrap();
assert!(approx_eq(msg1 + msg2, 23.01608));