Repository: tokio-rs/tokio
File: tokio/src/time/interval.rs (Rust)

Code before:
    ///
    /// use std::time::Duration;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let mut interval = time::interval(Duration::from_millis(100));
    ///     interval.tick().await;
    ///
    ///     time::sleep(Duration::from_millis(50)).await;
    ///
    ///     let after = Duration::from_millis(20);
    ///     interval.reset_after(after);
    ///
    ///     interval.tick().await;
    ///     interval.tick().await;
    ///
    ///     // approximately 170ms have elapsed.
    /// }
    /// ```
    pub fn reset_after(&mut self, after: Duration) {
        self.delay.as_mut().reset(Instant::now() + after);
    }

    /// Resets the interval to a [`crate::time::Instant`] deadline.
    ///
    /// This method ignores [`MissedTickBehavior`] strategy.
    ///
    /// # Examples
    ///
    /// ```
    /// use tokio::time::{self, Instant};
    ///
    /// use std::time::Duration;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let mut interval = time::interval(Duration::from_millis(100));
    ///     interval.tick().await;
    ///
    ///     time::sleep(Duration::from_millis(50)).await;
    ///
    ///     let deadline = Instant::now() + Duration::from_millis(30);
    ///     interval.reset_at(deadline);
    ///
    ///     interval.tick().await;
    ///     interval.tick().await;
    ///
    ///     // approximately 180ms have elapsed.
    /// }
    /// ```
    pub fn reset_at(&mut self, deadline: Instant) {

Review comment (suggestion):
It might be better to rephrase this as:

> Sets the next tick to expire at the given instant. If the instant is in the past, then the `MissedTickBehavior` strategy will be used to catch up. If the instant is in the future, then the next tick will complete at the given instant, even if that means that it will sleep for longer than the duration of this `Interval`. If the `Interval` had any missed ticks before calling this method, then those are discarded.

Code after:
    /// This is equivalent to calling `reset_at(Instant::now() + after)`.
    ///
    /// # Examples
    ///
    /// ```
    /// use tokio::time;
    ///
    /// use std::time::Duration;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let mut interval = time::interval(Duration::from_millis(100));
    ///     interval.tick().await;
    ///
    ///     time::sleep(Duration::from_millis(50)).await;
    ///
    ///     let after = Duration::from_millis(20);
    ///     interval.reset_after(after);
    ///
    ///     interval.tick().await;
    ///     interval.tick().await;
    ///
    ///     // approximately 170ms have elapsed.
    /// }
    /// ```
    pub fn reset_after(&mut self, after: Duration) {
        self.delay.as_mut().reset(Instant::now() + after);
    }

    /// Resets the interval to a [`crate::time::Instant`] deadline.
    ///
    /// Sets the next tick to expire at the given instant. If the instant is in
    /// the past, then the [`MissedTickBehavior`] strategy will be used to
    /// catch up. If the instant is in the future, then the next tick will
    /// complete at the given instant, even if that means that it will sleep for
    /// longer than the duration of this [`Interval`]. If the [`Interval`] had
    /// any missed ticks before calling this method, then those are discarded.
    ///
    /// # Examples
    ///
    /// ```
    /// use tokio::time::{self, Instant};
    ///
    /// use std::time::Duration;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let mut interval = time::interval(Duration::from_millis(100));
    ///     interval.tick().await;
    ///
    ///     time::sleep(Duration::from_millis(50)).await;