expression
Periodic interval and first tick
An interval maintains a sequence of scheduled instants. Its first tick is immediately available. Await subsequent ticks to follow the schedule; the fixture examines scheduled instants, not measured execution latency. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 2 Common mistake: Assuming the first tick always waits for a full period.
Formal Syntax & Structure
rust syntaxrust
tokio::time::interval(period); interval.tick().awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use tokio::time::{interval, Duration}; let mut ticks = interval(Duration::from_secs(2)); let first = ticks.tick().await; let second = ticks.tick().await; println!("{}", (second - first).as_secs());}