diff --git a/server/src/main.rs b/server/src/main.rs index 6b11247..6b7e13b 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -700,8 +700,10 @@ fn main() { } // ensure work continues, even if no queries registered, - // s.t. the sequencer continues issuing commands - worker.step(); + // s.t. the sequencer continues issuing commands. + // If there is nothing to do, park `until_next()` activation + // in scheduler is ready. + worker.step_or_park(Some(server.scheduler.borrow().until_next().unwrap_or(Duration::from_millis(100)))); server.context.internal.advance().expect("failed to advance domain"); diff --git a/src/server/scheduler.rs b/src/server/scheduler.rs index 4d9b057..d652a7d 100644 --- a/src/server/scheduler.rs +++ b/src/server/scheduler.rs @@ -35,6 +35,21 @@ impl Scheduler { false } } + /// Returns the duration until the next activation in `activator_queue` + /// from `now()`. If no activations are present returns None. + pub fn until_next(&self) -> Option { + if let Some(ref timed_activator) = self.activator_queue.peek() { + // timed_activator.at.check_duration_since(Instant::now()).unwrap_or(Duration::from_millies(0)) + let now = Instant::now(); + if timed_activator.at > now { + Some(timed_activator.at.duration_since(now)) + } else { + Some(Duration::from_millis(0)) + } + } else { + None + } + } /// Schedule activation at the specified instant. No hard /// guarantees on when the activator will actually be triggered.