Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Last active January 3, 2016 04:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanzab/8411680 to your computer and use it in GitHub Desktop.
Save brendanzab/8411680 to your computer and use it in GitHub Desktop.
use std::comm::{Port, Chan};
enum Event {
Pos(int, int),
}
fn main() {
let (port, chan) = Chan::new();
spawn(proc() handle_events(port));
run_event_loop(chan);
}
fn handle_events(port: Port<Event>) {
let mut curr_x: int;
let mut curr_y: int;
for x in port.iter() {
match x {
Pos(x, y) => {
curr_x = x;
curr_y = y;
}
}
println!("Updated current position: ({}, {})", curr_x, curr_y);
}
}
fn run_event_loop(chan: Chan<Event>) {
// just testing = we don't actually loop
chan.send(Pos(3, 4));
chan.send(Pos(0, -2));
chan.send(Pos(-3, 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment