Struct wheel_timer::WheelTimer
[−]
[src]
pub struct WheelTimer<T> { // some fields omitted }
A simple wheel timer implementation with a fixed ring size.
Methods
impl<T> WheelTimer<T>
fn new(max_interval: usize) -> WheelTimer<T>
Creates a new timer with the specified max interval.
Example
use wheel_timer::WheelTimer; let mut timer: WheelTimer<usize> = WheelTimer::new(20);
fn size(&self) -> usize
Returns the number of items currently scheduled.
Example
use wheel_timer::WheelTimer; let mut timer: WheelTimer<usize> = WheelTimer::new(20); timer.schedule(4, 1); timer.schedule(7, 1); timer.schedule(1, 1); assert_eq!(timer.size(), 3);
fn schedule(&mut self, ticks: usize, value: T)
Schedules a new value, available after ticks
have passed.
Example
use wheel_timer::WheelTimer; let mut timer: WheelTimer<usize> = WheelTimer::new(20); timer.schedule(4, 7); // schedule value 7 for 4 ticks
fn tick(&mut self) -> Vec<T>
Tick the timer, returning the node at the current tick.
Example
use wheel_timer::WheelTimer; let mut timer: WheelTimer<usize> = WheelTimer::new(20); timer.schedule(3, 4); // schedule value 4 for 3 ticks timer.tick(); timer.tick(); timer.tick(); let result = timer.tick(); // vec![4] assert_eq!(result.len(), 1);
Trait Implementations
impl<T> Iterator for WheelTimer<T>
Iterator implementation allows for using the wheel timer in a for loop.
Example
use wheel_timer::WheelTimer; let mut timer: WheelTimer<usize> = WheelTimer::new(20); for result in timer { // result is a vector of the values at that step }