From 365efec24a5755817810782304be6ed7ede23bb6 Mon Sep 17 00:00:00 2001 From: Douman Date: Tue, 24 Jul 2018 09:08:49 +0300 Subject: [PATCH] Add Interval::interval shortcut for a better usability (#492) --- tokio-timer/src/interval.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tokio-timer/src/interval.rs b/tokio-timer/src/interval.rs index 25cf34554..80d09600e 100644 --- a/tokio-timer/src/interval.rs +++ b/tokio-timer/src/interval.rs @@ -1,5 +1,7 @@ use Delay; +use clock; + use futures::{Future, Stream, Poll}; use std::time::{Instant, Duration}; @@ -18,6 +20,8 @@ impl Interval { /// Create a new `Interval` that starts at `at` and yields every `duration` /// interval after that. /// + /// Note that when it starts, it produces item too. + /// /// The `duration` argument must be a non-zero duration. /// /// # Panics @@ -29,6 +33,19 @@ impl Interval { Interval::new_with_delay(Delay::new(at), duration) } + /// Creates new `Interval` that yields with interval of `duration`. + /// + /// The function is shortcut for `Interval::new(Instant::now() + duration, duration)`. + /// + /// The `duration` argument must be a non-zero duration. + /// + /// # Panics + /// + /// This function panics if `duration` is zero. + pub fn new_interval(duration: Duration) -> Interval { + Interval::new(clock::now() + duration, duration) + } + pub(crate) fn new_with_delay(delay: Delay, duration: Duration) -> Interval { Interval { delay,