2 unstable releases

Uses old Rust 2015

0.1.0 May 14, 2016
0.0.1 May 1, 2015

#5 in #recv

Download history 71/week @ 2024-04-07 96/week @ 2024-04-14 81/week @ 2024-04-21 82/week @ 2024-04-28 90/week @ 2024-05-05 85/week @ 2024-05-12 75/week @ 2024-05-19 85/week @ 2024-05-26 93/week @ 2024-06-02 35/week @ 2024-06-09 74/week @ 2024-06-16 60/week @ 2024-06-23 18/week @ 2024-06-30 27/week @ 2024-07-07 67/week @ 2024-07-14 69/week @ 2024-07-21

187 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