Expand description
Time tracking
This module provides a number of types for executing code after a set period of time.
-
Delayis a future that does no work and completes at a specificInstantin time. -
Intervalis a stream yielding a value at a fixed period. It is initialized with aDurationand repeatedly yields each time the duration elapses. -
Timeout: Wraps a future or stream, setting an upper bound to the amount of time it is allowed to execute. If the future or stream does not complete in time, then it is canceled and an error is returned. -
DelayQueue: A queue where items are returned once the requested delay has expired.
These types are sufficient for handling a large number of scenarios involving time.
These types must be used from within the context of the Runtime.
§Examples
Wait 100ms and print “Hello World!”
use kayrx_timer::delay_for;
use std::time::Duration;
use kayrx_karx;
fn main() {
kayrx_karx::exec(async {
delay_for(Duration::from_millis(100)).await;
println!("100 ms have elapsed");
});
}
Require that an operation takes no more than 300ms. Note that this uses the
timeout function on the FutureExt trait. This trait is included in the
prelude.
use kayrx_timer::{timeout, Duration};
async fn long_future() {
// do work here
}
let res = timeout(Duration::from_secs(1), long_future()).await;
if res.is_err() {
println!("operation timed out");
}Modules§
- delay_
queue - A queue of delayed elements.
Structs§
- Delay
- Future returned by
delay_untilanddelay_for. - Delay
Queue - A queue of delayed elements.
- Duration
- A
Durationtype to represent a span of time, typically used for system timeouts. - Elapsed
- Error returned by
Timeout. - Error
- Errors encountered by the timer implementation.
- Instant
- A measurement of the system clock, useful for talking to external entities like the file system or other processes.
- Interval
- Stream returned by
intervalandinterval_at. - Throttle
- Stream for the
throttlefunction. - Timeout
- Future returned by
timeoutandtimeout_at.
Functions§
- delay_
for - Wait until
durationhas elapsed. - delay_
until - Wait until
deadlineis reached. - interval
- Creates new
Intervalthat yields with interval ofduration. The first tick completes immediately. - interval_
at - Creates new
Intervalthat yields with interval ofperiodwith the first tick completing atat. - pause
- Pause time
- resume
- Resume time
- throttle
- Slow down a stream by enforcing a delay between items. They will be produced not more often than the specified interval.
- timeout
- Require a
Futureto complete before the specified duration has elapsed. - timeout_
at - Require a
Futureto complete before the specified instant in time.