Created
August 25, 2016 09:58
-
-
Save MindFlavor/4e816d5eff2ddebc4262bd927f6a8c0e 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 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