Rename Sleep to Delay (#270)

This patch renames `Sleep` from tokio-timer and the tokio facade to
`Delay`. Given that the future does not actually put anything to sleep,
the `Delay` name feels more appropriate.

Fixes #263
This commit is contained in:
Carl Lerche
2018-03-30 14:21:48 -07:00
committed by GitHub
parent baa2502ec6
commit ea172537aa
12 changed files with 220 additions and 224 deletions
+10 -10
View File
@@ -1,4 +1,4 @@
use Sleep;
use Delay;
use futures::{Future, Stream, Poll};
@@ -8,7 +8,7 @@ use std::time::{Instant, Duration};
#[derive(Debug)]
pub struct Interval {
/// Future that completes the next time the `Interval` yields a value.
sleep: Sleep,
delay: Delay,
/// The duration between values yielded by `Interval`.
duration: Duration,
@@ -26,12 +26,12 @@ impl Interval {
pub fn new(at: Instant, duration: Duration) -> Interval {
assert!(duration > Duration::new(0, 0), "`duration` must be non-zero.");
Interval::new_with_sleep(Sleep::new(at), duration)
Interval::new_with_delay(Delay::new(at), duration)
}
pub(crate) fn new_with_sleep(sleep: Sleep, duration: Duration) -> Interval {
pub(crate) fn new_with_delay(delay: Delay, duration: Duration) -> Interval {
Interval {
sleep,
delay,
duration,
}
}
@@ -42,15 +42,15 @@ impl Stream for Interval {
type Error = ::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
// Wait for the sleep to be done
let _ = try_ready!(self.sleep.poll());
// Wait for the delay to be done
let _ = try_ready!(self.delay.poll());
// Get the `now` by looking at the `sleep` deadline
let now = self.sleep.deadline();
// Get the `now` by looking at the `delay` deadline
let now = self.delay.deadline();
// The next interval value is `duration` after the one that just
// yielded.
self.sleep.reset(now + self.duration);
self.delay.reset(now + self.duration);
// Return the current instant
Ok(Some(now).into())