• Home
  • Raw
  • Download

Lines Matching full:interval

9 /// Creates new [`Interval`] that yields with interval of `period`. The first
12 /// by calling [`set_missed_tick_behavior`](Interval::set_missed_tick_behavior).
14 /// An interval will tick indefinitely. At any time, the [`Interval`] value can
15 /// be dropped. This cancels the interval.
31 /// let mut interval = time::interval(Duration::from_millis(10));
33 /// interval.tick().await; // ticks immediately
34 /// interval.tick().await; // ticks after 10ms
35 /// interval.tick().await; // ticks after 10ms
41 /// A simple example using `interval` to execute a task every two seconds.
43 /// The difference between `interval` and [`sleep`] is that an [`Interval`]
45 /// may wait for a shorter time than the duration specified for the interval
62 /// let mut interval = time::interval(time::Duration::from_secs(2));
64 /// interval.tick().await;
71 /// [`.tick().await`]: Interval::tick
73 pub fn interval(period: Duration) -> Interval { in interval() function
78 /// Creates new [`Interval`] that yields with interval of `period` with the
81 /// by calling [`set_missed_tick_behavior`](Interval::set_missed_tick_behavior).
83 /// An interval will tick indefinitely. At any time, the [`Interval`] value can
84 /// be dropped. This cancels the interval.
98 /// let mut interval = interval_at(start, Duration::from_millis(10));
100 /// interval.tick().await; // ticks after 50ms
101 /// interval.tick().await; // ticks after 10ms
102 /// interval.tick().await; // ticks after 10ms
108 pub fn interval_at(start: Instant, period: Duration) -> Interval { in interval_at() argument
118 ) -> 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.
496 /// Resets the interval to complete one period after the current time.
511 /// let mut interval = time::interval(Duration::from_millis(100));
513 /// interval.tick().await;
516 /// interval.reset();
518 /// interval.tick().await;
519 /// interval.tick().await;
528 /// Resets the interval immediately.
543 /// let mut interval = time::interval(Duration::from_millis(100));
545 /// interval.tick().await;
548 /// interval.reset_immediately();
550 /// interval.tick().await;
551 /// interval.tick().await;
560 /// Resets the interval after the specified [`std::time::Duration`].
575 /// let mut interval = time::interval(Duration::from_millis(100));
576 /// interval.tick().await;
581 /// interval.reset_after(after);
583 /// interval.tick().await;
584 /// interval.tick().await;
593 /// Resets the interval to a [`crate::time::Instant`] deadline.
599 /// longer than the duration of this [`Interval`]. If the [`Interval`] had
611 /// let mut interval = time::interval(Duration::from_millis(100));
612 /// interval.tick().await;
617 /// interval.reset_at(deadline);
619 /// interval.tick().await;
620 /// interval.tick().await;
639 /// Returns the period of the interval.