Created
December 4, 2013 06:40
-
-
Save Torwegia/7783305 to your computer and use it in GitHub Desktop.
Why does the first one work, but not the second?
The compiler complains of a capture of a moved value.
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 works() { | |
let (port, chan): (Port<int>, Chan<int>) = stream(); | |
do spawn { | |
chan.send(42); | |
} | |
println(port.recv().to_str()); | |
} | |
fn noWorks() { | |
let (port, chan): (Port<int>, Chan<int>) = stream(); | |
for i in range(0, 100) { | |
do spawn { | |
chan.send(i); | |
} | |
} | |
while port.peek() { | |
println(port.recv().to_str()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The solution was to make a shared channel and clone it for each task. Thanks to Eridius on #rust