expression
Reset an interval schedule
Reset schedules the next tick relative to the current time, ignoring the old missed-tick policy for that reset. This is different from changing the period. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Expecting reset to change the configured period.
Formal Syntax & Structure
rust syntaxrust
interval.reset(); interval.tick().awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use tokio::time::{interval, Duration, Instant}; let period = Duration::from_secs(3); let mut ticks = interval(period); ticks.tick().await; let anchor = Instant::now(); ticks.reset(); let next = ticks.tick().await; println!("{}", next - anchor == period);}