Last active
January 3, 2016 04:49
-
-
Save brendanzab/8411680 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
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