Skip to content

Instantly share code, notes, and snippets.

@Torwegia
Created December 4, 2013 06:40
Show Gist options
  • Save Torwegia/7783305 to your computer and use it in GitHub Desktop.
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.
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());
}
}
@Torwegia
Copy link
Author

Torwegia commented Dec 4, 2013

The solution was to make a shared channel and clone it for each task. Thanks to Eridius on #rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment