Skip to content

Instantly share code, notes, and snippets.

@gterzian
Last active August 7, 2018 21:58
Show Gist options
  • Save gterzian/d73edbff1e3dc796d6b2421e97411cf7 to your computer and use it in GitHub Desktop.
Save gterzian/d73edbff1e3dc796d6b2421e97411cf7 to your computer and use it in GitHub Desktop.
// Results chan, to get the final merged results to the main thread
let (results_chan, results_port) = channel();
// Gen chan, to get generated numbers from the "generator".
let (gen_chan, gen_port) = channel();
// Share the sender of the results chan to the merge component.
let merge_chan = merge(results_chan);
// Start the workers, each worker receives a clone of the "merge chan sender".
let mut square_workers: VecDeque<Sender<PipelineMsg>> = vec![square(merge_chan.clone()),
square(merge_chan.clone())]
.into_iter()
.collect();
// Start the generator, passing along the "gen chan sender"
generate(gen_chan);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment