Commit 45fdcba8 authored by Ralf's avatar Ralf
Browse files

add some cool stuff which compiles

parent 1f351bd8
......@@ -22,6 +22,57 @@ struct State {
run: Box<FnOnce(Actors, Receiver<Event>) -> (Actors, Receiver<Event>, Option<State>) + 'static>,
}
#[must_use]
enum EventHandlerResult {
Continue,
CancelEvent,
QuitLoop,
}
#[must_use]
enum EventsHandledResult {
ShuttingDown,
Timeout,
Quit,
}
struct Environment {
events: Receiver<Event>,
}
struct EventHandler<'a> {
run: Box<FnMut(Event) -> EventHandlerResult + 'a>
}
impl Environment {
fn handle_events(&mut self, d: Duration, mut handlers: Vec<EventHandler>) -> EventsHandledResult {
let timeout_chan = timeout_chan(d);
loop {
let events = &self.events;
chan_select! {
timeout_chan.recv() => return EventsHandledResult::Timeout,
events.recv() -> ev => {
match ev {
Some(ev) => {
for handler in handlers.iter_mut() {
match (handler.run)(ev) {
EventHandlerResult::Continue => {},
EventHandlerResult::CancelEvent => break,
EventHandlerResult::QuitLoop => return EventsHandledResult::Quit,
}
}
}
None => return EventsHandledResult::Timeout,
}
}
}
}
unreachable!()
}
}
impl State {
fn new<F>(f: F) -> State
where F: FnOnce(Actors, Receiver<Event>) -> (Actors, Receiver<Event>, Option<State>) + 'static {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment