[−][src]Module ticktock::timer
Interval-timer
Interval timers can be used to periodically perform an action or mutate a stored value. Values are owned by the timer itself, but can be retrieved.
The timer does not run in a separate thread, but rather expects to be triggered from the outside occasionally, with time being passed in usually to save on syscalls.
Example:
use std::time; use ticktock::Timer; let now = time::Instant::now(); let mut heartbeat = Timer::apply( |_, count| { *count += 1; *count }, 0, ) .every(time::Duration::from_millis(500)) .start(now); for i in 0..10 { let now = time::Instant::now(); if let Some(n) = heartbeat.update(now) { println!("Heartbeat: {}", n); } }
Structs
Timer | |
TimerBuilder | A timer builder |