Expand description
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::thread::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");
}
Functions§
- oneshot
- Starts a timer which after
duration
will issue a single.send(())
on the other side of the returnedReceiver<()>
. - oneshot_
ms - Starts a timer which after
ms
milliseconds will issue a single.send(())
on the other side of the returnedReciever<()>
. - periodic
- Starts a timer which, every
duration
, will issue a single.send(())
on the other side of the returnedReceiver<()>
. - periodic_
after - Starts a timer which, every
duration
after an initial delay ofstart
, will issue.send(())
on the other side of the returnedReciever<()>
. - periodic_
ms - Starts a timer which, every
ms
milliseconds, will issue.send(())
on the other side of the returnedReciever<()>
.