Last active
August 7, 2018 22:00
-
-
Save gterzian/4130d85391e2ead5c98e55b5e4e9205e to your computer and use it in GitHub Desktop.
This file contains 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 square(merge_chan: Sender<PipelineMsg>) -> Sender<PipelineMsg> { | |
let (chan, port) = channel(); | |
let _ = thread::Builder::new().spawn(move || { | |
// Iteration will stop, | |
// once the sender returned by "square" is dropped. | |
for msg in port { | |
let num = match msg { | |
PipelineMsg::Generated(num) => num, | |
_ => panic!("unexpected message receiving at square stage"), | |
}; | |
// Sending squared numbers on to the "merge" stage... | |
let _ = merge_chan.send(PipelineMsg::Squared(num * num)); | |
} | |
}); | |
// Sharing our sender with the world... | |
chan | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment