Lines Matching full:interval
10 /// Creates new [`Interval`] that yields with interval of `period`. The first
13 /// by calling [`set_missed_tick_behavior`](Interval::set_missed_tick_behavior).
15 /// An interval will tick indefinitely. At any time, the [`Interval`] value can
16 /// be dropped. This cancels the interval.
32 /// let mut interval = time::interval(Duration::from_millis(10));
34 /// interval.tick().await; // ticks immediately
35 /// interval.tick().await; // ticks after 10ms
36 /// interval.tick().await; // ticks after 10ms
42 /// A simple example using `interval` to execute a task every two seconds.
44 /// The difference between `interval` and [`sleep`] is that an [`Interval`]
46 /// may wait for a shorter time than the duration specified for the interval
63 /// let mut interval = time::interval(time::Duration::from_secs(2));
65 /// interval.tick().await;
72 /// [`.tick().await`]: Interval::tick
74 pub fn interval(period: Duration) -> Interval { in interval() function
79 /// Creates new [`Interval`] that yields with interval of `period` with the
82 /// by calling [`set_missed_tick_behavior`](Interval::set_missed_tick_behavior).
84 /// An interval will tick indefinitely. At any time, the [`Interval`] value can
85 /// be dropped. This cancels the interval.
99 /// let mut interval = interval_at(start, Duration::from_millis(10));
101 /// interval.tick().await; // ticks after 50ms
102 /// interval.tick().await; // ticks after 10ms
103 /// interval.tick().await; // ticks after 10ms
109 pub fn interval_at(start: Instant, period: Duration) -> Interval { in interval_at() argument
119 ) -> Interval { in internal_interval_at() argument
126 concrete_type = "Interval", in internal_interval_at()
140 Interval { in internal_interval_at()
149 /// Defines the behavior of an [`Interval`] when it misses a tick.
151 /// Sometimes, an [`Interval`]'s tick is missed. For example, consider the
161 /// let mut interval = time::interval(Duration::from_millis(2));
163 /// interval.tick().await;
171 /// [`Interval::tick()`].
173 /// By default, when a tick is missed, [`Interval`] fires ticks as quickly as it
176 /// [`Interval`] to exhibit. Each variant represents a different strategy.
185 /// When this strategy is used, [`Interval`] schedules ticks "normally" (the
189 /// when `Burst` is used (the [`Instant`]s that [`tick`](Interval::tick)
203 /// use tokio::time::{interval, Duration};
208 /// let mut interval = interval(Duration::from_millis(50));
211 /// interval.tick().await;
214 /// // The `Interval` has missed a tick
217 /// interval.tick().await;
219 /// // Since we are more than 100ms after the start of `interval`, this will
221 /// interval.tick().await;
224 /// // 150ms after the start of `interval`
225 /// interval.tick().await;
228 /// interval.tick().await;
230 /// // Since we have gotten to 200ms after the start of `interval`, this
232 /// interval.tick().await;
236 /// This is the default behavior when [`Interval`] is created with
237 /// [`interval`] and [`interval_at`].
246 /// When this strategy is used and [`Interval`] has missed a tick, instead
262 /// use tokio::time::{interval, Duration, MissedTickBehavior};
267 /// let mut interval = interval(Duration::from_millis(50));
268 /// interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
271 /// // The `Interval` has missed a tick
274 /// interval.tick().await;
282 /// interval.tick().await;
288 /// [`tick`]: Interval::tick
294 /// When this strategy is used, [`Interval`] schedules the next tick to fire
296 /// `start` (the point where [`Interval`] first ticked). Like [`Burst`], all
313 /// use tokio::time::{interval, Duration, MissedTickBehavior};
318 /// let mut interval = interval(Duration::from_millis(50));
319 /// interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
322 /// // The `Interval` has missed a tick
325 /// interval.tick().await;
328 /// // `interval`, which is the closest multiple of `period` from the start
329 /// // of `interval` after the call to `tick` up above.
330 /// interval.tick().await;
358 "too much time has elapsed since the interval was supposed to tick", in next_timeout()
381 /// Interval returned by [`interval`] and [`interval_at`].
387 /// An `Interval` can be turned into a `Stream` with [`IntervalStream`].
392 pub struct Interval { struct
393 /// Future that completes the next time the `Interval` yields a value.
396 /// The duration between values yielded by `Interval`. argument
399 /// The strategy `Interval` should use when a tick is missed. argument
406 impl Interval { implementation
407 /// Completes when the next instant in the interval has been reached.
423 /// let mut interval = time::interval(Duration::from_millis(10));
425 /// interval.tick().await;
427 /// interval.tick().await;
428 /// interval.tick().await;
440 "Interval::tick", in tick()
450 /// Polls for the next instant in the interval to be reached.
491 /// Resets the interval to complete one period after the current time.
504 /// let mut interval = time::interval(Duration::from_millis(100));
506 /// interval.tick().await;
509 /// interval.reset();
511 /// interval.tick().await;
512 /// interval.tick().await;
531 /// Returns the period of the interval.