Skip to content

Commit

Permalink
Clean up main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ekr committed Jul 30, 2024
1 parent b1620b3 commit 26592fe
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,32 @@ impl Context {
}

pub fn execute(&mut self) {
// Execute callbacks if there are any in the queue
loop {
let callback = self.callback_queue.pop_front();
match callback {
Some(callback) => callback(self),
None => break,
}
}
// Start plan loop
loop {
let timed_plan = self.plan_queue.get_next_timed_plan();
match timed_plan {
Some(timed_plan) => {
self.current_time = timed_plan.time;
(timed_plan.callback)(self);
loop {
let callback = self.callback_queue.pop_front();
match callback {
Some(callback) => callback(self),
None => break,
}
}
let mut executed = false;

// First execute callbacks.
loop {
let callback = self.callback_queue.pop_front();
match callback {
Some(callback) => {
executed = true;
callback(self)
},
None => break,
}
None => break,
}

// Now execute the first timed plan.
if let Some(timed_plan) = self.plan_queue.get_next_timed_plan() {
executed = true;
self.current_time = timed_plan.time;
(timed_plan.callback)(self);
}

// If nothing happened, then we are done.
if !executed {
break;
}
}
}
Expand Down

0 comments on commit 26592fe

Please sign in to comment.