#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

#38 in #mio

Download history 34/week @ 2024-03-31 35/week @ 2024-04-07 31/week @ 2024-04-14 48/week @ 2024-04-21 13/week @ 2024-04-28 20/week @ 2024-05-05 40/week @ 2024-05-12 17/week @ 2024-05-19 8/week @ 2024-05-26 55/week @ 2024-06-02 20/week @ 2024-06-09 24/week @ 2024-06-16 31/week @ 2024-06-23 3/week @ 2024-06-30 8/week @ 2024-07-07 11/week @ 2024-07-14

55 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.1MB
~18K SLoC