hjul

Struct Runner

Source
pub struct Runner { /* private fields */ }

Implementations§

Source§

impl Runner

Source

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 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);
Source

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

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§

Source§

impl Debug for Runner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Runner

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.