pub fn interval(period: Duration) -> IntervalExpand description
Creates new Interval that yields with interval of duration. The first
tick completes immediately.
An interval will tick indefinitely. At any time, the Interval value can be
dropped. This cancels the interval.
This function is equivalent to interval_at(Instant::now(), period).
§Panics
This function panics if period is zero.
§Examples
use kayrx_timer::{self, Duration};
use kayrx_karx;
fn main() {
kayrx_karx::exec(async {
let mut interval = timer::interval(Duration::from_millis(10));
interval.tick().await;
interval.tick().await;
interval.tick().await;
// approximately 20ms have elapsed.
});
}