summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Alvarez <j@yabit.io>2020-10-08 22:35:12 -0500
committerGitHub <noreply@github.com>2020-10-08 20:35:12 -0700
commit60d81bbe10faf344ea18438a1c5ecb9173e6ec52 (patch)
tree4a6b64401944b62ffa872147e5738eb28e70d4ec
parentb704c53b9cc76eaf8c9c6585f8444c4515d27728 (diff)
time: rename `Delay` future to `Sleep` (#2932)
-rw-r--r--tokio-test/src/io.rs4
-rw-r--r--tokio-test/tests/block_on.rs2
-rw-r--r--tokio-util/src/time/delay_queue.rs4
-rw-r--r--tokio/src/lib.rs6
-rw-r--r--tokio/src/macros/select.rs26
-rw-r--r--tokio/src/runtime/handle.rs2
-rw-r--r--tokio/src/runtime/mod.rs4
-rw-r--r--tokio/src/stream/throttle.rs6
-rw-r--r--tokio/src/stream/timeout.rs6
-rw-r--r--tokio/src/sync/mod.rs10
-rw-r--r--tokio/src/time/clock.rs2
-rw-r--r--tokio/src/time/driver/entry.rs10
-rw-r--r--tokio/src/time/driver/mod.rs18
-rw-r--r--tokio/src/time/error.rs2
-rw-r--r--tokio/src/time/interval.rs4
-rw-r--r--tokio/src/time/mod.rs6
-rw-r--r--tokio/src/time/sleep.rs (renamed from tokio/src/time/delay.rs)38
-rw-r--r--tokio/src/time/tests/mod.rs10
-rw-r--r--tokio/src/time/tests/test_sleep.rs (renamed from tokio/src/time/tests/test_delay.rs)114
-rw-r--r--tokio/src/time/timeout.rs8
-rw-r--r--tokio/src/time/wheel/mod.rs2
-rw-r--r--tokio/tests/macros_select.rs4
-rw-r--r--tokio/tests/rt_common.rs6
-rw-r--r--tokio/tests/stream_timeout.rs8
-rw-r--r--tokio/tests/time_sleep.rs (renamed from tokio/tests/time_delay.rs)70
25 files changed, 186 insertions, 186 deletions
diff --git a/tokio-test/src/io.rs b/tokio-test/src/io.rs
index 3d04a58a..7cfad2ec 100644
--- a/tokio-test/src/io.rs
+++ b/tokio-test/src/io.rs
@@ -20,7 +20,7 @@
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio::sync::mpsc;
-use tokio::time::{self, Delay, Duration, Instant};
+use tokio::time::{self, Duration, Instant, Sleep};
use futures_core::ready;
use std::collections::VecDeque;
@@ -67,7 +67,7 @@ enum Action {
struct Inner {
actions: VecDeque<Action>,
waiting: Option<Instant>,
- sleep: Option<Delay>,
+ sleep: Option<Sleep>,
read_wait: Option<Waker>,
rx: mpsc::UnboundedReceiver<Action>,
}
diff --git a/tokio-test/tests/block_on.rs b/tokio-test/tests/block_on.rs
index 280471df..efaaf510 100644
--- a/tokio-test/tests/block_on.rs
+++ b/tokio-test/tests/block_on.rs
@@ -18,7 +18,7 @@ fn async_fn() {
}
#[test]
-fn test_delay() {
+fn test_sleep() {
let deadline = Instant::now() + Duration::from_millis(100);
block_on(async {
diff --git a/tokio-util/src/time/delay_queue.rs b/tokio-util/src/time/delay_queue.rs
index 92c922b8..7a1d1acf 100644
--- a/tokio-util/src/time/delay_queue.rs
+++ b/tokio-util/src/time/delay_queue.rs
@@ -7,7 +7,7 @@
use crate::time::wheel::{self, Wheel};
use futures_core::ready;
-use tokio::time::{sleep_until, Delay, Duration, Error, Instant};
+use tokio::time::{sleep_until, Duration, Error, Instant, Sleep};
use slab::Slab;
use std::cmp;
@@ -138,7 +138,7 @@ pub struct DelayQueue<T> {
expired: Stack<T>,
/// Delay expiring when the *first* item in the queue expires
- delay: Option<Delay>,
+ delay: Option<Sleep>,
/// Wheel polling state
wheel_now: u64,
diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs
index 948ac888..326b1395 100644
--- a/tokio/src/lib.rs
+++ b/tokio/src/lib.rs
@@ -25,7 +25,7 @@
//! provides a few major components:
//!
//! * Tools for [working with asynchronous tasks][tasks], including
-//! [synchronization primitives and channels][sync] and [timeouts, delays, and
+//! [synchronization primitives and channels][sync] and [timeouts, sleeps, and
//! intervals][time].
//! * APIs for [performing asynchronous I/O][io], including [TCP and UDP][net] sockets,
//! [filesystem][fs] operations, and [process] and [signal] management.
@@ -183,13 +183,13 @@
//!
//! The [`tokio::time`] module provides utilities for tracking time and
//! scheduling work. This includes functions for setting [timeouts][timeout] for
-//! tasks, [delaying][delay] work to run in the future, or [repeating an operation at an
+//! tasks, [sleeping][sleep] work to run in the future, or [repeating an operation at an
//! interval][interval].
//!
//! In order to use `tokio::time`, the "time" feature flag must be enabled.
//!
//! [`tokio::time`]: crate::time
-//! [delay]: crate::time::sleep()
+//! [sleep]: crate::time::sleep()
//! [interval]: crate::time::interval()
//! [timeout]: crate::time::timeout()
//!
diff --git a/tokio/src/macros/select.rs b/tokio/src/macros/select.rs
index 8f15f9aa..b63abdd2 100644
--- a/tokio/src/macros/select.rs
+++ b/tokio/src/macros/select.rs
@@ -63,9 +63,9 @@
/// Given that `if` preconditions are used to disable `select!` branches, some
/// caution must be used to avoid missing values.
///
-/// For example, here is **incorrect** usage of `delay` with `if`. The objective
+/// For example, here is **incorrect** usage of `sleep` with `if`. The objective
/// is to repeatedly run an asynchronous task for up to 50 milliseconds.
-/// However, there is a potential for the `delay` completion to be missed.
+/// However, there is a potential for the `sleep` completion to be missed.
///
/// ```no_run
/// use tokio::time::{self, Duration};
@@ -76,11 +76,11 @@
///
/// #[tokio::main]
/// async fn main() {
-/// let mut delay = time::sleep(Duration::from_millis(50));
+/// let mut sleep = time::sleep(Duration::from_millis(50));
///
-/// while !delay.is_elapsed() {
+/// while !sleep.is_elapsed() {
/// tokio::select! {
-/// _ = &mut delay, if !delay.is_elapsed() => {
+/// _ = &mut sleep, if !sleep.is_elapsed() => {
/// println!("operation timed out");
/// }
/// _ = some_async_work() => {
@@ -91,11 +91,11 @@
/// }
/// ```
///
-/// In the above example, `delay.is_elapsed()` may return `true` even if
-/// `delay.poll()` never returned `Ready`. This opens up a potential race
-/// condition where `delay` expires between the `while !delay.is_elapsed()`
+/// In the above example, `sleep.is_elapsed()` may return `true` even if
+/// `sleep.poll()` never returned `Ready`. This opens up a potential race
+/// condition where `sleep` expires between the `while !sleep.is_elapsed()`
/// check and the call to `select!` resulting in the `some_async_work()` call to
-/// run uninterrupted despite the delay having elapsed.
+/// run uninterrupted despite the sleep having elapsed.
///
/// One way to write the above example without the race would be:
///
@@ -109,11 +109,11 @@
///
/// #[tokio::main]
/// async fn main() {
-/// let mut delay = time::sleep(Duration::from_millis(50));
+/// let mut sleep = time::sleep(Duration::from_millis(50));
///
/// loop {
/// tokio::select! {
-/// _ = &mut delay => {
+/// _ = &mut sleep => {
/// println!("operation timed out");
/// break;
/// }
@@ -226,7 +226,7 @@
/// #[tokio::main]
/// async fn main() {
/// let mut stream = stream::iter(vec![1, 2, 3]);
-/// let mut delay = time::sleep(Duration::from_secs(1));
+/// let mut sleep = time::sleep(Duration::from_secs(1));
///
/// loop {
/// tokio::select! {
@@ -237,7 +237,7 @@
/// break;
/// }
/// }
-/// _ = &mut delay => {
+/// _ = &mut sleep => {
/// println!("timeout");
/// break;
/// }
diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs
index dfcc5e97..d48b6242 100644
--- a/tokio/src/runtime/handle.rs
+++ b/tokio/src/runtime/handle.rs
@@ -28,7 +28,7 @@ pub(crate) struct Handle {
impl Handle {
/// Enter the runtime context. This allows you to construct types that must
- /// have an executor available on creation such as [`Delay`] or [`TcpStream`].
+ /// have an executor available on creation such as [`Sleep`] or [`TcpStream`].
/// It will also allow you to call methods such as [`tokio::spawn`].
pub(crate) fn enter<F, R>(&self, f: F) -> R
where
diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs
index 22109f7d..8e70db85 100644
--- a/tokio/src/runtime/mod.rs
+++ b/tokio/src/runtime/mod.rs
@@ -450,10 +450,10 @@ impl Runtime {
}
/// Enter the runtime context. This allows you to construct types that must
- /// have an executor available on creation such as [`Delay`] or [`TcpStream`].
+ /// have an executor available on creation such as [`Sleep`] or [`TcpStream`].
/// It will also allow you to call methods such as [`tokio::spawn`].
///
- /// [`Delay`]: struct@crate::time::Delay
+ /// [`Sleep`]: struct@crate::time::Sleep
/// [`TcpStream`]: struct@crate::net::TcpStream
/// [`tokio::spawn`]: fn@crate::spawn
///
diff --git a/tokio/src/stream/throttle.rs b/tokio/src/stream/throttle.rs
index 1200b384..8f4a256d 100644
--- a/tokio/src/stream/throttle.rs
+++ b/tokio/src/stream/throttle.rs
@@ -1,7 +1,7 @@
//! Slow down a stream by enforcing a delay between items.
use crate::stream::Stream;
-use crate::time::{Delay, Duration, Instant};
+use crate::time::{Duration, Instant, Sleep};
use std::future::Future;
use std::marker::Unpin;
@@ -17,7 +17,7 @@ where
let delay = if duration == Duration::from_millis(0) {
None
} else {
- Some(Delay::new_timeout(Instant::now() + duration, duration))
+ Some(Sleep::new_timeout(Instant::now() + duration, duration))
};
Throttle {
@@ -34,7 +34,7 @@ pin_project! {
#[must_use = "streams do nothing unless polled"]
pub struct Throttle<T> {
// `None` when duration is zero.
- delay: Option<Delay>,
+ delay: Option<Sleep>,
duration: Duration,
// Set to true when `delay` has returned ready, but `stream` hasn't.
diff --git a/tokio/src/stream/timeout.rs b/tokio/src/stream/timeout.rs
index b8a2024f..b16000c6 100644
--- a/tokio/src/stream/timeout.rs
+++ b/tokio/src/stream/timeout.rs
@@ -1,5 +1,5 @@
use crate::stream::{Fuse, Stream};
-use crate::time::{Delay, Elapsed, Instant};
+use crate::time::{Elapsed, Instant, Sleep};
use core::future::Future;
use core::pin::Pin;
@@ -14,7 +14,7 @@ pin_project! {
pub struct Timeout<S> {
#[pin]
stream: Fuse<S>,
- deadline: Delay,
+ deadline: Sleep,
duration: Duration,
poll_deadline: bool,
}
@@ -23,7 +23,7 @@ pin_project! {
impl<S: Stream> Timeout<S> {
pub(super) fn new(stream: S, duration: Duration) -> Self {
let next = Instant::now() + duration;
- let deadline = Delay::new_timeout(next, duration);
+ let deadline = Sleep::new_timeout(next, duration);
Timeout {
stream: Fuse::new(stream),
diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs
index 294b0b50..4919ad8e 100644
--- a/tokio/src/sync/mod.rs
+++ b/tokio/src/sync/mod.rs
@@ -359,11 +359,11 @@
//! let mut conf = rx.borrow().clone();
//!
//! let mut op_start = Instant::now();
-//! let mut delay = time::sleep_until(op_start + conf.timeout);
+//! let mut sleep = time::sleep_until(op_start + conf.timeout);
//!
//! loop {
//! tokio::select! {
-//! _ = &mut delay => {
+//! _ = &mut sleep => {
//! // The operation elapsed. Restart it
//! op.set(my_async_operation());
//!
@@ -371,14 +371,14 @@
//! op_start = Instant::now();
//!
//! // Restart the timeout
-//! delay = time::sleep_until(op_start + conf.timeout);
+//! sleep = time::sleep_until(op_start + conf.timeout);
//! }
//! _ = rx.changed() => {
//! conf = rx.borrow().clone();
//!
//! // The configuration has been updated. Update the
-//! // `delay` using the new `timeout` value.
-//! delay.reset(op_start + conf.timeout);
+//! // `sleep` using the new `timeout` value.
+//! sleep.reset(op_start + conf.timeout);
//! }
//! _ = &mut op => {
//! // The operation completed!
diff --git a/tokio/src/time/clock.rs b/tokio/src/time/clock.rs
index bd67d7a3..80682d59 100644
--- a/tokio/src/time/clock.rs
+++ b/tokio/src/time/clock.rs
@@ -58,7 +58,7 @@ cfg_test_util! {
/// The current value of `Instant::now()` is saved and all subsequent calls
/// to `Instant::now()` until the timer wheel is checked again will return the saved value.
/// Once the timer wheel is checked, time will immediately advance to the next registered
- /// `Delay`. This is useful for running tests that depend on time.
+ /// `Sleep`. This is useful for running tests that depend on time.
///
/// # Panics
///
diff --git a/tokio/src/time/driver/entry.rs b/tokio/src/time/driver/entry.rs
index 20f8e1c6..20a3a8c5 100644
--- a/tokio/src/time/driver/entry.rs
+++ b/tokio/src/time/driver/entry.rs
@@ -11,7 +11,7 @@ use std::sync::{Arc, Weak};
use std::task::{self, Poll};
use std::u64;
-/// Internal state shared between a `Delay` instance and the timer.
+/// Internal state shared between a `Sleep` instance and the timer.
///
/// This struct is used as a node in two intrusive data structures:
///
@@ -28,7 +28,7 @@ pub(crate) struct Entry {
time: CachePadded<UnsafeCell<Time>>,
/// Timer internals. Using a weak pointer allows the timer to shutdown
- /// without all `Delay` instances having completed.
+ /// without all `Sleep` instances having completed.
///
/// When empty, it means that the entry has not yet been linked with a
/// timer instance.
@@ -69,8 +69,8 @@ pub(crate) struct Entry {
/// When the entry expires, relative to the `start` of the timer
/// (Inner::start). This is only used by the timer.
///
- /// A `Delay` instance can be reset to a different deadline by the thread
- /// that owns the `Delay` instance. In this case, the timer thread will not
+ /// A `Sleep` instance can be reset to a different deadline by the thread
+ /// that owns the `Sleep` instance. In this case, the timer thread will not
/// immediately know that this has happened. The timer thread must know the
/// last deadline that it saw as it uses this value to locate the entry in
/// its wheel.
@@ -94,7 +94,7 @@ pub(crate) struct Entry {
pub(crate) prev_stack: UnsafeCell<*const Entry>,
}
-/// Stores the info for `Delay`.
+/// Stores the info for `Sleep`.
#[derive(Debug)]
pub(crate) struct Time {
pub(crate) deadline: Instant,
diff --git a/tokio/src/time/driver/mod.rs b/tokio/src/time/driver/mod.rs
index 5ece7c72..94e905b4 100644
--- a/tokio/src/time/driver/mod.rs
+++ b/tokio/src/time/driver/mod.rs
@@ -20,12 +20,12 @@ use std::sync::Arc;
use std::usize;
use std::{cmp, fmt};
-/// Time implementation that drives [`Delay`][delay], [`Interval`][interval], and [`Timeout`][timeout].
+/// Time implementation that drives [`Sleep`][sleep], [`Interval`][interval], and [`Timeout`][timeout].
///
/// A `Driver` instance tracks the state necessary for managing time and
-/// notifying the [`Delay`][delay] instances once their deadlines are reached.
+/// notifying the [`Sleep`][sleep] instances once their deadlines are reached.
///
-/// It is expected that a single instance manages many individual [`Delay`][delay]
+/// It is expected that a single instance manages many individual [`Sleep`][sleep]
/// instances. The `Driver` implementation is thread-safe and, as such, is able
/// to handle callers from across threads.
///
@@ -36,9 +36,9 @@ use std::{cmp, fmt};
/// The driver has a resolution of one millisecond. Any unit of time that falls
/// between milliseconds are rounded up to the next millisecond.
///
-/// When an instance is dropped, any outstanding [`Delay`][delay] instance that has not
+/// When an instance is dropped, any outstanding [`Sleep`][sleep] instance that has not
/// elapsed will be notified with an error. At this point, calling `poll` on the
-/// [`Delay`][delay] instance will result in panic.
+/// [`Sleep`][sleep] instance will result in panic.
///
/// # Implementation
///
@@ -65,14 +65,14 @@ use std::{cmp, fmt};
/// * Level 5: 64 x ~12 day slots.
///
/// When the timer processes entries at level zero, it will notify all the
-/// `Delay` instances as their deadlines have been reached. For all higher
+/// `Sleep` instances as their deadlines have been reached. For all higher
/// levels, all entries will be redistributed across the wheel at the next level
-/// down. Eventually, as time progresses, entries with [`Delay`][delay] instances will
+/// down. Eventually, as time progresses, entries with [`Sleep`][sleep] instances will
/// either be canceled (dropped) or their associated entries will reach level
/// zero and be notified.
///
/// [paper]: http://www.cs.columbia.edu/~nahum/w6998/papers/ton97-timing-wheels.pdf
-/// [delay]: crate::time::Delay
+/// [sleep]: crate::time::Sleep
/// [timeout]: crate::time::Timeout
/// [interval]: crate::time::Interval
#[derive(Debug)]
@@ -138,7 +138,7 @@ where
/// Returns a handle to the timer.
///
- /// The `Handle` is how `Delay` instances are created. The `Delay` instances
+ /// The `Handle` is how `Sleep` instances are created. The `Sleep` instances
/// can either be created directly or the `Handle` instance can be passed to
/// `with_default`, setting the timer as the default timer for the execution
/// context.
diff --git a/tokio/src/time/error.rs b/tokio/src/time/error.rs
index a022f78f..7154a330 100644
--- a/tokio/src/time/error.rs
+++ b/tokio/src/time/error.rs
@@ -13,7 +13,7 @@ use std::fmt;
/// succeed in the future.
///
/// * `at_capacity` occurs when a timer operation is attempted, but the timer
-/// instance is currently handling its maximum number of outstanding delays.
+/// instance is currently handling its maximum number of outstanding sleep instances.
/// In this case, the operation is not able to be performed at the current
/// moment, and `at_capacity` is returned. This is a transient error, i.e., at
/// some point in the future, if the operation is attempted again, it might
diff --git a/tokio/src/time/interval.rs b/tokio/src/time/interval.rs
index 1b443a36..c7c58e17 100644
--- a/tokio/src/time/interval.rs
+++ b/tokio/src/time/interval.rs
@@ -1,5 +1,5 @@
use crate::future::poll_fn;
-use crate::time::{sleep_until, Delay, Duration, Instant};
+use crate::time::{sleep_until, Duration, Instant, Sleep};
use std::future::Future;
use std::pin::Pin;
@@ -115,7 +115,7 @@ pub fn interval_at(start: Instant, period: Duration) -> Interval {
#[derive(Debug)]
pub struct Interval {
/// Future that completes the next time the `Interval` yields a value.
- delay: Delay,
+ delay: Sleep,
/// The duration between values yielded by `Interval`.
period: Duration,
diff --git a/tokio/src/time/mod.rs b/tokio/src/time/mod.rs
index a68e11b5..41148641 100644
--- a/tokio/src/time/mod.rs
+++ b/tokio/src/time/mod.rs
@@ -3,7 +3,7 @@
//! This module provides a number of types for executing code after a set period
//! of time.
//!
-//! * `Delay` is a future that does no work and completes at a specific `Instant`
+//! * `Sleep` is a future that does no work and completes at a specific `Instant`
//! in time.
//!
//! * `Interval` is a stream yielding a value at a fixed period. It is
@@ -93,8 +93,8 @@ pub(crate) use self::clock::Clock;
#[cfg(feature = "test-util")]
pub use clock::{advance, pause, resume};
-mod delay;
-pub use delay::{sleep, sleep_until, Delay};
+mod sleep;
+pub use sleep::{sleep, sleep_until, Sleep};
pub(crate) mod driver;
diff --git a/tokio/src/time/delay.rs b/tokio/src/time/sleep.rs
index 9364860d..9f836b0f 100644
--- a/tokio/src/time/delay.rs
+++ b/tokio/src/time/sleep.rs
@@ -8,16 +8,16 @@ use std::task::{self, Poll};
/// Waits until `deadline` is reached.
///
-/// No work is performed while awaiting on the delay to complete. The delay
+/// No work is performed while awaiting on the sleep future to complete. `Sleep`
/// operates at millisecond granularity and should not be used for tasks that
/// require high-resolution timers.
///
/// # Cancellation
///
-/// Canceling a delay is done by dropping the returned future. No additional
+/// Canceling a sleep instance is done by dropping the returned future. No additional
/// cleanup work is required.
-pub fn sleep_until(deadline: Instant) -> Delay {
- Delay::new_timeout(deadline, Duration::from_millis(0))
+pub fn sleep_until(deadline: Instant) -> Sleep {
+ Sleep::new_timeout(deadline, Duration::from_millis(0))
}
/// Waits until `duration` has elapsed.
@@ -25,7 +25,7 @@ pub fn sleep_until(deadline: Instant) -> Delay {
/// Equivalent to `sleep_until(Instant::now() + duration)`. An asynchronous
/// analog to `std::thread::sleep`.
///
-/// No work is performed while awaiting on the delay to complete. The delay
+/// No work is performed while awaiting on the sleep future to complete. `Sleep`
/// operates at millisecond granularity and should not be used for tasks that
/// require high-resolution timers.
///
@@ -33,7 +33,7 @@ pub fn sleep_until(deadline: Instant) -> Delay {
///
/// # Cancellation
///
-/// Canceling a delay is done by dropping the returned future. No additional
+/// Canceling a sleep instance is done by dropping the returned future. No additional
/// cleanup work is required.
///
/// # Examples
@@ -51,7 +51,7 @@ pub fn sleep_until(deadline: Instant) -> Delay {
/// ```
///
/// [`interval`]: crate::time::interval()
-pub fn sleep(duration: Duration) -> Delay {
+pub fn sleep(duration: Duration) -> Sleep {
sleep_until(Instant::now() + duration)
}
@@ -59,19 +59,19 @@ pub fn sleep(duration: Duration) -> Delay {
/// [`sleep_until`](sleep_until).
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
-pub struct Delay {
- /// The link between the `Delay` instance and the timer that drives it.
+pub struct Sleep {
+ /// The link between the `Sleep` instance and the timer that drives it.
///
/// This also stores the `deadline` value.
entry: Arc<Entry>,
}
-impl Delay {
- pub(crate) fn new_timeout(deadline: Instant, duration: Duration) -> Delay {
+impl Sleep {
+ pub(crate) fn new_timeout(deadline: Instant, duration: Duration) -> Sleep {
let handle = Handle::current();
let entry = Entry::new(&handle, deadline, duration);
- Delay { entry }
+ Sleep { entry }
}
/// Returns the instant at which the future will complete.
@@ -79,16 +79,16 @@ impl Delay {
self.entry.time_ref().deadline
}
- /// Returns `true` if the `Delay` has elapsed
+ /// Returns `true` if `Sleep` has elapsed.
///
- /// A `Delay` is elapsed when the requested duration has elapsed.
+ /// A `Sleep` instance is elapsed when the requested duration has elapsed.
pub fn is_elapsed(&self) -> bool {
self.entry.is_elapsed()
}
- /// Resets the `Delay` instance to a new deadline.
+ /// Resets the `Sleep` instance to a new deadline.
///
- /// Calling this function allows changing the instant at which the `Delay`
+ /// Calling this function allows changing the instant at which the `Sleep`
/// future completes without having to create new associated state.
///
/// This function can be called both before and after the future has
@@ -112,14 +112,14 @@ impl Delay {
}
}
-impl Future for Delay {
+impl Future for Sleep {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
// `poll_elapsed` can return an error in two cases:
//
// - AtCapacity: this is a pathological case where far too many
- // delays have been scheduled.
+ // sleep instances have been scheduled.
// - Shutdown: No timer has been setup, which is a mis-use error.
//
// Both cases are extremely rare, and pretty accurately fit into
@@ -132,7 +132,7 @@ impl Future for Delay {
}
}
-impl Drop for Delay {
+impl Drop for Sleep {
fn drop(&mut self) {
Entry::cancel(&self.entry);
}
diff --git a/tokio/src/time/tests/mod.rs b/tokio/src/time/tests/mod.rs
index a043d65e..fae67da9 100644
--- a/tokio/src/time/tests/mod.rs
+++ b/tokio/src/time/tests/mod.rs
@@ -1,4 +1,4 @@
-mod test_delay;
+mod test_sleep;
use crate::time::{self, Instant};
use std::time::Duration;
@@ -8,15 +8,15 @@ fn assert_sync<T: Sync>() {}
#[test]
fn registration_is_send_and_sync() {
- use crate::time::delay::Delay;
+ use crate::time::sleep::Sleep;
- assert_send::<Delay>();
- assert_sync::<Delay>();
+ assert_send::<Sleep>();
+ assert_sync::<Sleep>();
}
#[test]
#[should_panic]
-fn delay_is_eager() {
+fn sleep_is_eager() {
let when = Instant::now() + Duration::from_millis(100);
let _ = time::sleep_until(when);
}
diff --git a/tokio/src/time/tests/test_delay.rs b/tokio/src/time/tests/test_sleep.rs
index b732e458..c8d931a8 100644
--- a/tokio/src/time/tests/test_delay.rs
+++ b/tokio/src/time/tests/test_sleep.rs
@@ -25,12 +25,12 @@ fn frozen_utility_returns_correct_advanced_duration() {
}
#[test]
-fn immediate_delay() {
+fn immediate_sleep() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
let when = clock.now();
- let mut e = task::spawn(delay_until(&handle, when));
+ let mut e = task::spawn(sleep_until(&handle, when));
assert_ready_ok!(poll!(e));
@@ -41,15 +41,15 @@ fn immediate_delay() {
}
#[test]
-fn delayed_delay_level_0() {
+fn delayed_sleep_level_0() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
for &i in &[1, 10, 60] {
- // Create a `Delay` that elapses in the future
- let mut e = task::spawn(delay_until(&handle, start + ms(i)));
+ // Create a `Sleep` that elapses in the future
+ let mut e = task::spawn(sleep_until(&handle, start + ms(i)));
- // The delay has not elapsed.
+ // The sleep instance has not elapsed.
assert_pending!(poll!(e));
assert_ok!(driver.park());
@@ -60,13 +60,13 @@ fn delayed_delay_level_0() {
}
#[test]
-fn sub_ms_delayed_delay() {
+fn sub_ms_delayed_sleep() {
let (mut driver, clock, handle) = setup();
for _ in 0..5 {
let deadline = clock.now() + ms(1) + Duration::new(0, 1);
- let mut e = task::spawn(delay_until(&handle, deadline));
+ let mut e = task::spawn(sleep_until(&handle, deadline));
assert_pending!(poll!(e));
@@ -80,14 +80,14 @@ fn sub_ms_delayed_delay() {
}
#[test]
-fn delayed_delay_wrapping_level_0() {
+fn delayed_sleep_wrapping_level_0() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
assert_ok!(driver.park_timeout(ms(5)));
assert_eq!(clock.now() - start, ms(5));
- let mut e = task::spawn(delay_until(&handle, clock.now() + ms(60)));
+ let mut e = task::spawn(sleep_until(&handle, clock.now() + ms(60)));
assert_pending!(poll!(e));
@@ -106,15 +106,15 @@ fn timer_wrapping_with_higher_levels() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
- // Set delay to hit level 1
- let mut e1 = task::spawn(delay_until(&handle, clock.now() + ms(64)));
+ // Set sleep to hit level 1
+ let mut e1 = task::spawn(sleep_until(&handle, clock.now() + ms(64)));
assert_pending!(poll!(e1));
// Turn a bit
assert_ok!(driver.park_timeout(ms(5)));
// Set timeout such that it will hit level 0, but wrap
- let mut e2 = task::spawn(delay_until(&handle, clock.now() + ms(60)));
+ let mut e2 = task::spawn(sleep_until(&handle, clock.now() + ms(60)));
assert_pending!(poll!(e2));
// This should result in s1 firing
@@ -131,14 +131,14 @@ fn timer_wrapping_with_higher_levels() {
}
#[test]
-fn delay_with_deadline_in_past() {
+fn sleep_with_deadline_in_past() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
- // Create `Delay` that elapsed immediately.
- let mut e = task::spawn(delay_until(&handle, clock.now() - ms(100)));
+ // Create `Sleep` that elapsed immediately.
+ let mut e = task::spawn(sleep_until(&handle, clock.now() - ms(100)));
- // Even though the delay expires in the past, it is not ready yet
+ // Even though the `Sleep` expires in the past, it is not ready yet
// because the timer must observe it.
assert_ready_ok!(poll!(e));
@@ -150,37 +150,37 @@ fn delay_with_deadline_in_past() {
}
#[test]
-fn delayed_delay_level_1() {
+fn delayed_sleep_level_1() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
- // Create a `Delay` that elapses in the future
- let mut e = task::spawn(delay_until(&handle, clock.now() + ms(234)));
+ // Create a `Sleep` that elapses in the future
+ let mut e = task::spawn(sleep_until(&handle, clock.now() + ms(234)));
- // The delay has not elapsed.
+ // The sleep has not elapsed.
assert_pending!(poll!(e));
// Turn the timer, this will wake up to cascade the timer down.
assert_ok!(driver.park_timeout(ms(1000)));
assert_eq!(clock.now() - start, ms(192));
- // The delay has not elapsed.
+ // The sleep has not elapsed.
assert_pending!(poll!(e));
// Turn the timer again
assert_ok!(driver.park_timeout(ms(1000)));
assert_eq!(clock.now() - start, ms(234));
- // The delay has elapsed.
+ // The sleep has elapsed.
assert_ready_ok!(poll!(e));
let (mut driver, clock, handle) = setup();
let start = clock.now();
- // Create a `Delay` that elapses in the future
- let mut e = task::spawn(delay_until(&handle, clock.now() + ms(234)));
+ // Create a `Sleep` that elapses in the future
+ let mut e = task::spawn(sleep_until(&handle, clock.now() + ms(234)));
- // The delay has not elapsed.
+ // The sleep has not elapsed.
assert_pending!(poll!(e));
// Turn the timer with a smaller timeout than the cascade.
@@ -193,14 +193,14 @@ fn delayed_delay_level_1() {
assert_ok!(driver.park_timeout(ms(1000)));
assert_eq!(clock.now() - start, ms(192));
- // The delay has not elapsed.
+ // The sleep has not elapsed.
assert_pending!(poll!(e));
// Turn the timer again
assert_ok!(driver.park_timeout(ms(1000)));
assert_eq!(clock.now() - start,