2 unstable releases

Uses old Rust 2015

0.1.0 May 14, 2016
0.0.1 May 1, 2015

#6 in #receivers

Download history 87/week @ 2024-11-15 120/week @ 2024-11-22 90/week @ 2024-11-29 187/week @ 2024-12-06 153/week @ 2024-12-13 52/week @ 2024-12-20 29/week @ 2024-12-27 114/week @ 2025-01-03 181/week @ 2025-01-10 202/week @ 2025-01-17 160/week @ 2025-01-24 210/week @ 2025-01-31 189/week @ 2025-02-07 120/week @ 2025-02-14 135/week @ 2025-02-21 101/week @ 2025-02-28

576 downloads per month
Used in 5 crates (4 directly)

MIT license

11KB
209 lines

This module exposes functionality to create receivers that receive notifications after a specified period of time or at a specified frequency.

Build status

Documentation

Examples

At its simplest, oneshot_ms can be used to put the thread to sleep. Unlike with std:🧵:sleep, this could be used with Select to be waiting for one of several Receivers to fire.

use timer::oneshot_ms;

let timer = oneshot_ms(1500);
timer.recv().unwrap();
println!("1.5 seconds have elapsed.");

Periodic Receivers can be created using periodic_ms.

use timer::periodic_ms;

let tick = periodic_ms(2000);
thread::sleep_ms(1000);
let tock = periodic_ms(2000);
loop {
    tick.recv().unwrap();
    println!("Tick");
    tock.recv().unwrap();
    println!("Tock");
}

lib.rs:

This crate exposes functionality to create receivers that receive notifications after a specified period of time or at a specified frequency.

Examples

At its simplest, oneshot_ms can be used to put the thread to sleep. Unlike with std:🧵:sleep, this could be used with Select to be waiting for one of several Receivers to fire.

let timer = oneshot(Duration::from_millis(1500));
timer.recv().unwrap();
println!("1.5 seconds have elapsed.");

Periodic Receivers can be created using periodic_ms.

let tick = periodic(Duration::from_millis(2000));
thread::sleep_ms(1000);
let tock = periodic(Duration::from_millis(2000));

loop {
    tick.recv().unwrap();
    println!("Tick");
    tock.recv().unwrap();
    println!("Tock");
}

Dependencies

~14KB