Add Interval::interval shortcut for a better usability (#492)

This commit is contained in:
Douman
2018-07-23 23:08:49 -07:00
committed by Carl Lerche
parent 491f15827b
commit 365efec24a
+17
View File
@@ -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,