Skip to content

Instantly share code, notes, and snippets.

@gterzian
Last active August 8, 2018 17:34
Show Gist options
  • Save gterzian/fcf955a56c7ef96d8bc1ca77ddeffc72 to your computer and use it in GitHub Desktop.
Save gterzian/fcf955a56c7ef96d8bc1ca77ddeffc72 to your computer and use it in GitHub Desktop.
for msg in gen_port {
// Receive generated numbers from the "generate" stage.
let generated_num = match msg {
PipelineMsg::Generated(num) => num,
_ => panic!("unexpected message receiving from gen stage"),
};
// Cycle through the workers and distribute work.
let worker = square_workers.pop_front().unwrap();
let _ = worker.send(msg);
square_workers.push_back(worker);
if generated_num == 3 {
// Once we get the "last number" we need,
// we just stop iterating,
// dropping the gen_port, and stopping the generator thread.
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment