Skip to content

Commit

Permalink
Renaming change_hz to set_hz for consistency, deprecated the old method
Browse files Browse the repository at this point in the history
  • Loading branch information
DavJCosby committed Oct 4, 2024
1 parent 268b140 commit cda04be
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit cda04be

Please sign in to comment.