pub struct Runner { /* private fields */ }
Implementations§
Source§impl Runner
impl Runner
Sourcepub fn new(tick: Duration, slots: usize, capacity: usize) -> Runner
pub fn new(tick: Duration, slots: usize, capacity: usize) -> Runner
Creates a new Runner, which executes the associated timer callbacks
§Arguments
tick
: duration of a single tick. This determines the accuracy of the underlaying timer wheelslots
: Number of slots in the timer wheel.capacity
: Maximum number of timers which can be allocated for the wheel
§Note
The longest possible duration of any timer is tick
* slots
§Example
use hjul::Runner;
use std::time::Duration;
// allows 1024 timers, with duration up to 10s and 100ms accuracy
let runner = Runner::new(Duration::from_millis(100), 100, 1024);
Sourcepub fn timer<F>(&self, callback: F) -> Timer
pub fn timer<F>(&self, callback: F) -> Timer
Allocate a new (stopped) timer and associate it with the callback
§Arguments
callback
: Callback to execute whenever the timer fires (possible repeatedly, if reset).
§Example
let timer = runner.timer(|| println!("fired"));
// start the timer
timer.reset(Duration::from_millis(100));
// wait for timer to fire
thread::sleep(Duration::from_millis(1000));
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runner
impl !RefUnwindSafe for Runner
impl Send for Runner
impl Sync for Runner
impl Unpin for Runner
impl !UnwindSafe for Runner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more