From cda04be777a60d1f68dfdb8d40b405a7f490cc70 Mon Sep 17 00:00:00 2001 From: David Cosby Date: Thu, 3 Oct 2024 23:56:14 -0600 Subject: [PATCH] Renaming change_hz to set_hz for consistency, deprecated the old method --- src/scheduler/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 925dda6..dd27878 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -16,6 +16,7 @@ impl Default for Scheduler { } impl Scheduler { + /// Constructs a new Scheduler struct that can schedule tasks at the given frequency `target_hz`. pub fn new(target_hz: f32) -> Self { let target_delta = Duration::from_secs_f32(target_hz.recip()); Scheduler { @@ -25,10 +26,24 @@ impl Scheduler { } } + /// Allows you to change the frequency at which the scheduler tries to run tasks. + /// + /// Note: Deprecated in favor of [Scheduler::set_hz()] + /// ``` + #[deprecated] pub fn change_hz(&mut self, new_target_hz: f32) { self.target_delta = Duration::from_secs_f32(new_target_hz.recip()) } + /// Allows you to change the frequency at which the scheduler tries to run tasks. + pub fn set_hz(&mut self, new_target_hz: f32) { + self.target_delta = Duration::from_secs_f32(new_target_hz.recip()) + } + + pub fn hz(&self) -> f32 { + return self.target_delta.as_secs_f32().recip() + } + pub fn loop_forever(&mut self, mut task: impl FnMut()) -> ! { loop { task();