mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
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:
+10
-10
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user