Crate async_timing_util

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_MINS_MS
FIFTEEN_SECONDS_MS
FIVE_MINS_MS
FIVE_SECONDS_MS
ONE_DAY_MS
ONE_HOUR_MS
ONE_MIN_MS
ONE_SECOND_MS
ONE_WEEK_MS
SIX_HOURS_MS
TEN_MINS_MS
TEN_SECONDS_MS
THIRTY_DAYS_MS
THIRTY_MINS_MS
THIRTY_SECONDS_MS
THREE_DAYS_MS
THREE_HOURS_MS
THREE_MINS_MS
THREE_SECONDS_MS
TWELVE_HOURS_MS
TWO_DAYS_MS
TWO_HOURS_MS
TWO_MINS_MS
TWO_SECONDS_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. Returns current time 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”.