rtc-interval 0.1.0

Wall clock synchronized interval timers
Documentation

Async and sync intervals that are synced to the real-time-clock.

That means e.g. a 10-second interval will fire at 00:00:00, 00:00:10, 00:00:20, etc. instead of 10 seconds after the interval was started.

Note: for intervals shorter than 1 second does not sync to the real-time-clock, working as a regular interval only.

Examples

Sync

use rtc_interval::RtcInterval;
use std::time::Duration;

let mut interval = RtcInterval::new(Duration::from_secs(10));
loop {
    let t = interval.tick(); // blocks until the next 10-second boundary
    println!("tick at {}", t.as_secs());
}

Async

use rtc_interval::AsyncRtcInterval;
use std::time::Duration;

let mut interval = AsyncRtcInterval::new(Duration::from_secs(10));
loop {
    let t = interval.tick().await; // waits until the next 10-second boundary
    println!("tick at {}", t.as_secs());
}