[][src]Struct hjul::Runner

pub struct Runner { /* fields omitted */ }

Methods

impl Runner[src]

pub fn new(tick: Duration, slots: usize, capacity: usize) -> Runner[src]

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 wheel
  • slots: 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);

pub fn timer<F>(&self, callback: F) -> Timer where
    F: 'static + Fn() + Send + Sync
[src]

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

impl Drop for Runner[src]

impl Debug for Runner[src]

Auto Trait Implementations

impl Send for Runner

impl Unpin for Runner

impl Sync for Runner

impl !UnwindSafe for Runner

impl !RefUnwindSafe for Runner

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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