skip_interval/examples/hello.rs

31 lines
765 B
Rust

use std::time::Instant;
use tokio::time::Interval;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let start = Instant::now();
let mut interval = short();
for _ in 0..5 {
interval.tick().await;
println!("{}", start.elapsed().as_millis());
}
let start = Instant::now();
let mut interval = long();
for _ in 0..5 {
interval.tick().await;
println!("{}", start.elapsed().as_millis());
}
}
fn long() -> Interval {
let mut interval = tokio::time::interval(std::time::Duration::from_millis(200));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
interval
}
// 80% reduction in character count
fn short() -> Interval {
skip_interval::from_millis(200)
}