Crate async_timing_util

Source
Expand description

§Async Timing Util

Convenient utilities for doing repeated tasks at precise intervals.

use async_timing_util::{Timelength, wait_until_timelength};
 
loop {
    let ts = wait_until_timelength(Timelength::OneHour).await;
    /// Do something async every hour, on the hour
    /// Runs at 00:00, 01:00, 02:00, etc.
}

Enums§

Timelength
Represents various standard lengths of time.

Constants§

EIGHT_HOURS_MS
FIFTEEN_MIN_MS
FIFTEEN_SECONDS_MS
FIVE_MIN_MS
FIVE_SECONDS_MS
ONE_DAY_MS
ONE_HOUR_MS
ONE_MIN_MS
ONE_SECOND_MS
ONE_WEEK_MS
SIX_HOURS_MS
TEN_MIN_MS
TEN_SECONDS_MS
THIRTY_DAYS_MS
THIRTY_MIN_MS
THIRTY_SECONDS_MS
THREE_DAY_MS
TWELVE_HOURS_MS
TWO_HOUR_MS
TWO_MIN_MS
TWO_WEEKS_MS

Functions§

get_timelength_in_ms
Converts a timelength into milliseconds.
last_timelength_interval
Gets the most recent complete interval of a given timelength.
unix_timestamp_ms
Gets the system time in unix milliseconds. Panics if SystemTime::duration_since returns an error.
wait_until
Sleeps until the target unix time. Panics if the target time is before the current time.
wait_until_timelength
Waits until the next even instance of the timelength. For example, Timelength::OneHour will wait until the next hour, eg 01:00, 02:00, plus the “additional_ms”.