Skip to content

Instantly share code, notes, and snippets.

@MindFlavor
Created August 25, 2016 09:58
Show Gist options
  • Save MindFlavor/4e816d5eff2ddebc4262bd927f6a8c0e to your computer and use it in GitHub Desktop.
Save MindFlavor/4e816d5eff2ddebc4262bd927f6a8c0e to your computer and use it in GitHub Desktop.
fn super_dumb_thread2() -> Vec<u64> {
let (sx, rx) = channel();
// here the thread steals the ownership
// of the send channel. That means it will
// drop the channel as soon as it finishes,
// signaling that no more data will be sent.
thread::spawn(move || {
for i in 0..100000000 {
if i % 10000 == 0 {
sx.send(i).unwrap();
}
}
// here sx will be dropped
});
let mut v = Vec::new();
while let Ok(i) = rx.recv() {
v.push(i);
}
v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment