[][src]Struct throttle_timer::ThrottleTimer

pub struct ThrottleTimer { /* fields omitted */ }

Methods

impl ThrottleTimer[src]

Example

use std::time::Duration;
use throttle_timer::ThrottleTimer;

let mut break_timer: ThrottleTimer = ThrottleTimer::new(Duration::from_secs(1_u64), &"Break");
let do_break_flag = break_timer.run(&mut || {});

// Timers always run when no previous runs
assert!(do_break_flag == true);
if do_break_flag {
    println!("timer do run flag is set to true")
}

// Run flag false as no time has passed
assert!(break_timer.run(&mut || {}) == false);

pub fn new(max_frequency: Duration, event_name: &'static str) -> Self[src]

pub const fn event_name(&self) -> &str[src]

pub const fn total_calls(&self) -> &usize[src]

pub const fn max_frequency(&self) -> &Duration[src]

pub const fn created_date(&self) -> SystemTime[src]

pub fn wait_time(&self) -> Duration[src]

pub fn print_stats(&self)[src]

Prints total calls and calls/sec

pub fn can_run(&mut self) -> bool[src]

Calling run() will check the last call time. If max frequency time has not passed the fn will return false. If max_frequency duration has passed since the last call then the fn will return true

pub fn run_throttle_cb(
    &mut self,
    success: &mut dyn FnMut(),
    throttled: &mut dyn FnMut()
) -> bool
[src]

pub fn run(&mut self, success: &mut dyn FnMut()) -> bool[src]

Calling run() will check the last call time. If max frequency time has not passed the fn will return false. If max_frequency duration has passed since the last call then the fn will return true

pub fn run_wait(&mut self, success: &mut dyn FnMut())[src]

Calling run() will check the last call time. If max frequency time has not passed the fn will return false. If max_frequency duration has passed since the last call then the fn will return true

pub fn run_with_msg(&mut self, success: &mut dyn FnMut()) -> bool[src]

Trait Implementations

impl Debug for ThrottleTimer[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]