#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

#36 in #mio

Download history 17/week @ 2023-12-03 9/week @ 2023-12-10 15/week @ 2023-12-17 32/week @ 2023-12-24 1/week @ 2024-01-07 36/week @ 2024-01-14 17/week @ 2024-01-21 7/week @ 2024-01-28 1/week @ 2024-02-04 13/week @ 2024-02-11 21/week @ 2024-02-18 30/week @ 2024-02-25 31/week @ 2024-03-03 16/week @ 2024-03-10 16/week @ 2024-03-17

94 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