Skip to content

Instantly share code, notes, and snippets.

@cdleary
Created April 9, 2013 02:16
Show Gist options
  • Save cdleary/5342392 to your computer and use it in GitHub Desktop.
Save cdleary/5342392 to your computer and use it in GitHub Desktop.
Example of Rust making me happy.
use core::task::task;
use core::comm::{stream, Port};
enum MyDataType {
CoolVariant(int),
CoolerVariant(~str)
}
fn spewer(port: Port<MyDataType>) {
loop {
let value = port.try_recv();
match value {
None => return,
Some(value) => io::println(fmt!("%?", value))
}
}
}
fn main() {
let (port, chan) = stream();
task().linked().spawn_with(port, spewer);
chan.send(CoolerVariant(~"Hello"));
chan.send(CoolVariant(42));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment