Last active
August 7, 2018 22:01
-
-
Save gterzian/d9f34ffcdfd5b50895177f0392ae9e0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn merge(merged_result_chan: Sender<PipelineMsg>) -> Sender<PipelineMsg> { | |
| let (chan, port) = channel(); | |
| let _ = thread::Builder::new().spawn(move || { | |
| // Iteration will stop when all senders are dropped. | |
| // This happens when the worker stop their iteration, | |
| // and drop their "merge_chan"... | |
| for msg in port { | |
| let squared = match msg { | |
| PipelineMsg::Squared(num) => num, | |
| _ => panic!("unexpected message receiving at merge stage"), | |
| }; | |
| // Sending "merged results" back to the main thread... | |
| let _ = merged_result_chan.send(PipelineMsg::Merged(squared)); | |
| } | |
| }); | |
| // Sharing the "merge_chan" with the world... | |
| chan | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment