#timer #callback #mio #mio-extra #timer-wheel

hjul

Simple and efficient timer abstraction on top of mio-extra. Every timer is associated with a callback which is executed whenever the timer expires, timers can be stopped and reset, in which case the callback might be executed multiple times. The primary intended application is one in which timers have a bounded maximum duration (e.g. at most 10 minutes) and have to be cancelled and restarted very often.

6 releases

0.2.2 May 22, 2020
0.2.1 Nov 21, 2019
0.2.0 Sep 22, 2019
0.1.2 Aug 26, 2019

#43 in #mio

Download history 50/week @ 2024-09-02 26/week @ 2024-09-09 22/week @ 2024-09-16 48/week @ 2024-09-23 16/week @ 2024-09-30 22/week @ 2024-10-07 9/week @ 2024-10-14 24/week @ 2024-10-21 3/week @ 2024-10-28 17/week @ 2024-11-04 13/week @ 2024-11-11 23/week @ 2024-11-18 15/week @ 2024-11-25 18/week @ 2024-12-02 32/week @ 2024-12-09 16/week @ 2024-12-16

82 downloads per month
Used in greenie

MIT license

16KB
251 lines

Stable Rust CI Status Beta Rust CI Status Nightly Rust CI Status

Hjul

Hjul is a thin wrapper around mio-extra timers. Example usage:

use hjul::Runner;
use std::thread;
use std::time::Duration;

let runner = Runner::new(Duration::from_millis(100), 100, 1024);
let timer = runner.timer(|| println!("fired"));

timer.start(Duration::from_millis(200));

// wait for timer to fire
thread::sleep(Duration::from_millis(500));

// start the timer again
timer.start(Duration::from_millis(200));

// stop timer immediately
timer.stop();

// start the timer again
timer.start(Duration::from_millis(200));

// timer is stopped when it goes out of scope

Full documentation at docs.rs/hjul

Dependencies

~0.8–1.2MB
~18K SLoC