2 unstable releases

Uses old Rust 2015

0.1.0 May 14, 2016
0.0.1 May 1, 2015

#1596 in Asynchronous

Download history 93/week @ 2024-12-17 42/week @ 2024-12-24 63/week @ 2024-12-31 119/week @ 2025-01-07 248/week @ 2025-01-14 132/week @ 2025-01-21 216/week @ 2025-01-28 205/week @ 2025-02-04 156/week @ 2025-02-11 109/week @ 2025-02-18 134/week @ 2025-02-25 87/week @ 2025-03-04 265/week @ 2025-03-11 251/week @ 2025-03-18 230/week @ 2025-03-25 150/week @ 2025-04-01

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

MIT license

11KB
209 lines

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");
}

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");
}

Dependencies

~14KB