summaryrefslogtreecommitdiffstats
path: root/tokio
diff options
context:
space:
mode:
authorJuan Alvarez <j@yabit.io>2020-10-01 02:24:33 -0500
committerGitHub <noreply@github.com>2020-10-01 09:24:33 +0200
commit53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5 (patch)
tree66f0b4c089729616b57bbb69b0a6351b45a0c898 /tokio
parent971ed2c6df9cb3bf3543a9c780662a0b4d1a8d40 (diff)
time: introduce `sleep` and `sleep_until` functions (#2826)
Diffstat (limited to 'tokio')
-rw-r--r--tokio/src/lib.rs2
-rw-r--r--tokio/src/macros/select.rs8
-rw-r--r--tokio/src/runtime/task/join.rs8
-rw-r--r--tokio/src/stream/mod.rs6
-rw-r--r--tokio/src/sync/mod.rs6
-rw-r--r--tokio/src/sync/mpsc/bounded.rs4
-rw-r--r--tokio/src/task/local.rs2
-rw-r--r--tokio/src/time/delay.rs19
-rw-r--r--tokio/src/time/delay_queue.rs10
-rw-r--r--tokio/src/time/driver/handle.rs4
-rw-r--r--tokio/src/time/instant.rs12
-rw-r--r--tokio/src/time/interval.rs12
-rw-r--r--tokio/src/time/mod.rs14
-rw-r--r--tokio/src/time/tests/mod.rs2
-rw-r--r--tokio/src/time/timeout.rs4
-rw-r--r--tokio/tests/async_send_sync.rs4
-rw-r--r--tokio/tests/macros_select.rs4
-rw-r--r--tokio/tests/process_issue_2174.rs2
-rw-r--r--tokio/tests/process_kill_on_drop.rs4
-rw-r--r--tokio/tests/rt_common.rs20
-rw-r--r--tokio/tests/stream_timeout.rs4
-rw-r--r--tokio/tests/task_local.rs2
-rw-r--r--tokio/tests/task_local_set.rs16
-rw-r--r--tokio/tests/time_delay.rs32
-rw-r--r--tokio/tests/time_delay_queue.rs74
-rw-r--r--tokio/tests/time_rt.rs6
26 files changed, 140 insertions, 141 deletions
diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs
index 4fe82cf2..1b0dad5d 100644
--- a/tokio/src/lib.rs
+++ b/tokio/src/lib.rs
@@ -189,7 +189,7 @@
//! In order to use `tokio::time`, the "time" feature flag must be enabled.
//!
//! [`tokio::time`]: crate::time
-//! [delay]: crate::time::delay_for()
+//! [delay]: 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 ffca0027..8f15f9aa 100644
--- a/tokio/src/macros/select.rs
+++ b/tokio/src/macros/select.rs
@@ -76,7 +76,7 @@
///
/// #[tokio::main]
/// async fn main() {
-/// let mut delay = time::delay_for(Duration::from_millis(50));
+/// let mut delay = time::sleep(Duration::from_millis(50));
///
/// while !delay.is_elapsed() {
/// tokio::select! {
@@ -103,13 +103,13 @@
/// use tokio::time::{self, Duration};
///
/// async fn some_async_work() {
-/// # time::delay_for(Duration::from_millis(10)).await;
+/// # time::sleep(Duration::from_millis(10)).await;
/// // do work
/// }
///
/// #[tokio::main]
/// async fn main() {
-/// let mut delay = time::delay_for(Duration::from_millis(50));
+/// let mut delay = time::sleep(Duration::from_millis(50));
///
/// loop {
/// tokio::select! {
@@ -226,7 +226,7 @@
/// #[tokio::main]
/// async fn main() {
/// let mut stream = stream::iter(vec![1, 2, 3]);
-/// let mut delay = time::delay_for(Duration::from_secs(1));
+/// let mut delay = time::sleep(Duration::from_secs(1));
///
/// loop {
/// tokio::select! {
diff --git a/tokio/src/runtime/task/join.rs b/tokio/src/runtime/task/join.rs
index ae776509..9b73353d 100644
--- a/tokio/src/runtime/task/join.rs
+++ b/tokio/src/runtime/task/join.rs
@@ -121,7 +121,7 @@ doc_rt_core! {
/// let original_task = task::spawn(async {
/// let _detached_task = task::spawn(async {
/// // Here we sleep to make sure that the first task returns before.
- /// time::delay_for(Duration::from_millis(10)).await;
+ /// time::sleep(Duration::from_millis(10)).await;
/// // This will be called, even though the JoinHandle is dropped.
/// println!("♫ Still alive ♫");
/// });
@@ -133,7 +133,7 @@ doc_rt_core! {
/// // We make sure that the new task has time to run, before the main
/// // task returns.
///
- /// time::delay_for(Duration::from_millis(1000)).await;
+ /// time::sleep(Duration::from_millis(1000)).await;
/// # }
/// ```
///
@@ -172,12 +172,12 @@ impl<T> JoinHandle<T> {
/// let mut handles = Vec::new();
///
/// handles.push(tokio::spawn(async {
- /// time::delay_for(time::Duration::from_secs(10)).await;
+ /// time::sleep(time::Duration::from_secs(10)).await;
/// true
/// }));
///
/// handles.push(tokio::spawn(async {
- /// time::delay_for(time::Duration::from_secs(10)).await;
+ /// time::sleep(time::Duration::from_secs(10)).await;
/// false
/// }));
///
diff --git a/tokio/src/stream/mod.rs b/tokio/src/stream/mod.rs
index 59e1482f..ec48392b 100644
--- a/tokio/src/stream/mod.rs
+++ b/tokio/src/stream/mod.rs
@@ -281,18 +281,18 @@ pub trait StreamExt: Stream {
/// tx1.send(2).await.unwrap();
///
/// // Let the other task send values
- /// time::delay_for(Duration::from_millis(20)).await;
+ /// time::sleep(Duration::from_millis(20)).await;
///
/// tx1.send(4).await.unwrap();
/// });
///
/// tokio::spawn(async move {
/// // Wait for the first task to send values
- /// time::delay_for(Duration::from_millis(5)).await;
+ /// time::sleep(Duration::from_millis(5)).await;
///
/// tx2.send(3).await.unwrap();
///
- /// time::delay_for(Duration::from_millis(25)).await;
+ /// time::sleep(Duration::from_millis(25)).await;
///
/// // Send the final value
/// tx2.send(5).await.unwrap();
diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs
index 6531931b..294b0b50 100644
--- a/tokio/src/sync/mod.rs
+++ b/tokio/src/sync/mod.rs
@@ -322,7 +322,7 @@
//! tokio::spawn(async move {
//! loop {
//! // Wait 10 seconds between checks
-//! time::delay_for(Duration::from_secs(10)).await;
+//! time::sleep(Duration::from_secs(10)).await;
//!
//! // Load the configuration file
//! let new_config = Config::load_from_file().await.unwrap();
@@ -359,7 +359,7 @@
//! let mut conf = rx.borrow().clone();
//!
//! let mut op_start = Instant::now();
-//! let mut delay = time::delay_until(op_start + conf.timeout);
+//! let mut delay = time::sleep_until(op_start + conf.timeout);
//!
//! loop {
//! tokio::select! {
@@ -371,7 +371,7 @@
//! op_start = Instant::now();
//!
//! // Restart the timeout
-//! delay = time::delay_until(op_start + conf.timeout);
+//! delay = time::sleep_until(op_start + conf.timeout);
//! }
//! _ = rx.changed() => {
//! conf = rx.borrow().clone();
diff --git a/tokio/src/sync/mpsc/bounded.rs b/tokio/src/sync/mpsc/bounded.rs
index 5e94e729..38fb753e 100644
--- a/tokio/src/sync/mpsc/bounded.rs
+++ b/tokio/src/sync/mpsc/bounded.rs
@@ -449,7 +449,7 @@ impl<T> Sender<T> {
///
/// ```rust
/// use tokio::sync::mpsc;
- /// use tokio::time::{delay_for, Duration};
+ /// use tokio::time::{sleep, Duration};
///
/// #[tokio::main]
/// async fn main() {
@@ -466,7 +466,7 @@ impl<T> Sender<T> {
///
/// while let Some(i) = rx.recv().await {
/// println!("got = {}", i);
- /// delay_for(Duration::from_millis(200)).await;
+ /// sleep(Duration::from_millis(200)).await;
/// }
/// }
/// ```
diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs
index 1d7b99d5..ccb9201e 100644
--- a/tokio/src/task/local.rs
+++ b/tokio/src/task/local.rs
@@ -95,7 +95,7 @@ cfg_rt_util! {
/// });
///
/// local.spawn_local(async move {
- /// time::delay_for(time::Duration::from_millis(100)).await;
+ /// time::sleep(time::Duration::from_millis(100)).await;
/// println!("goodbye {}", unsend_data)
/// });
///
diff --git a/tokio/src/time/delay.rs b/tokio/src/time/delay.rs
index 744c7e16..42ae4b08 100644
--- a/tokio/src/time/delay.rs
+++ b/tokio/src/time/delay.rs
@@ -15,14 +15,14 @@ use std::task::{self, Poll};
///
/// Canceling a delay is done by dropping the returned future. No additional
/// cleanup work is required.
-pub fn delay_until(deadline: Instant) -> Delay {
+pub fn sleep_until(deadline: Instant) -> Delay {
let registration = Registration::new(deadline, Duration::from_millis(0));
Delay { registration }
}
/// Waits until `duration` has elapsed.
///
-/// Equivalent to `delay_until(Instant::now() + duration)`. An asynchronous
+/// 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
@@ -41,23 +41,22 @@ pub fn delay_until(deadline: Instant) -> Delay {
/// Wait 100ms and print "100 ms have elapsed".
///
/// ```
-/// use tokio::time::{delay_for, Duration};
+/// use tokio::time::{sleep, Duration};
///
/// #[tokio::main]
/// async fn main() {
-/// delay_for(Duration::from_millis(100)).await;
+/// sleep(Duration::from_millis(100)).await;
/// println!("100 ms have elapsed");
/// }
/// ```
///
/// [`interval`]: crate::time::interval()
-#[cfg_attr(docsrs, doc(alias = "sleep"))]
-pub fn delay_for(duration: Duration) -> Delay {
- delay_until(Instant::now() + duration)
+pub fn sleep(duration: Duration) -> Delay {
+ sleep_until(Instant::now() + duration)
}
-/// Future returned by [`delay_until`](delay_until) and
-/// [`delay_for`](delay_for).
+/// Future returned by [`sleep`](sleep) and
+/// [`sleep_until`](sleep_until).
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Delay {
@@ -103,7 +102,7 @@ impl Future for Delay {
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 pathlogical case where far too many
+ // - AtCapacity: this is a pathological case where far too many
// delays have been scheduled.
// - Shutdown: No timer has been setup, which is a mis-use error.
//
diff --git a/tokio/src/time/delay_queue.rs b/tokio/src/time/delay_queue.rs
index 6f755eba..910f75fb 100644
--- a/tokio/src/time/delay_queue.rs
+++ b/tokio/src/time/delay_queue.rs
@@ -5,7 +5,7 @@
//! [`DelayQueue`]: struct@DelayQueue
use crate::time::wheel::{self, Wheel};
-use crate::time::{delay_until, Delay, Duration, Error, Instant};
+use crate::time::{sleep_until, Delay, Duration, Error, Instant};
use slab::Slab;
use std::cmp;
@@ -51,7 +51,7 @@ use std::task::{self, Poll};
/// # Implementation
///
/// The [`DelayQueue`] is backed by a separate instance of the same timer wheel used internally by
-/// Tokio's standalone timer utilities such as [`delay_for`]. Because of this, it offers the same
+/// Tokio's standalone timer utilities such as [`sleep`]. Because of this, it offers the same
/// performance and scalability benefits.
///
/// State associated with each entry is stored in a [`slab`]. This amortizes the cost of allocation,
@@ -118,7 +118,7 @@ use std::task::{self, Poll};
/// [`poll_expired`]: method@Self::poll_expired
/// [`Stream::poll_expired`]: method@Self::poll_expired
/// [`DelayQueue`]: struct@DelayQueue
-/// [`delay_for`]: fn@super::delay_for
+/// [`sleep`]: fn@super::sleep
/// [`slab`]: slab
/// [`capacity`]: method@Self::capacity
/// [`reserve`]: method@Self::reserve
@@ -330,7 +330,7 @@ impl<T> DelayQueue<T> {
if let Some(ref mut delay) = &mut self.delay {
delay.reset(delay_time);
} else {
- self.delay = Some(delay_until(delay_time));
+ self.delay = Some(sleep_until(delay_time));
}
}
@@ -734,7 +734,7 @@ impl<T> DelayQueue<T> {
// We poll the wheel to get the next value out before finding the next deadline.
let wheel_idx = self.wheel.poll(&mut self.poll, &mut self.slab);
- self.delay = self.next_deadline().map(delay_until);
+ self.delay = self.next_deadline().map(sleep_until);
if let Some(idx) = wheel_idx {
return Poll::Ready(Some(Ok(idx)));
diff --git a/tokio/src/time/driver/handle.rs b/tokio/src/time/driver/handle.rs
index f79f62b4..e9e53e56 100644
--- a/tokio/src/time/driver/handle.rs
+++ b/tokio/src/time/driver/handle.rs
@@ -25,9 +25,9 @@ impl Handle {
/// `Builder::enable_all()` are not included in the builder.
///
/// It can also panic whenever a timer is created outside of a Tokio
- /// runtime. That is why `rt.block_on(delay_for(...))` will panic,
+ /// runtime. That is why `rt.block_on(sleep(...))` will panic,
/// since the function is executed outside of the runtime.
- /// Whereas `rt.block_on(async {delay_for(...).await})` doesn't
+ /// Whereas `rt.block_on(async {sleep(...).await})` doesn't
/// panic. And this is because wrapping the function on an async makes it
/// lazy, and so gets executed inside the runtime successfuly without
/// panicking.
diff --git a/tokio/src/time/instant.rs b/tokio/src/time/instant.rs
index f2cb4bc9..e14a3004 100644
--- a/tokio/src/time/instant.rs
+++ b/tokio/src/time/instant.rs
@@ -50,12 +50,12 @@ impl Instant {
/// # Examples
///
/// ```
- /// use tokio::time::{Duration, Instant, delay_for};
+ /// use tokio::time::{Duration, Instant, sleep};
///
/// #[tokio::main]
/// async fn main() {
/// let now = Instant::now();
- /// delay_for(Duration::new(1, 0)).await;
+ /// sleep(Duration::new(1, 0)).await;
/// let new_now = Instant::now();
/// println!("{:?}", new_now.checked_duration_since(now));
/// println!("{:?}", now.checked_duration_since(new_now)); // None
@@ -71,12 +71,12 @@ impl Instant {
/// # Examples
///
/// ```
- /// use tokio::time::{Duration, Instant, delay_for};
+ /// use tokio::time::{Duration, Instant, sleep};
///
/// #[tokio::main]
/// async fn main() {
/// let now = Instant::now();
- /// delay_for(Duration::new(1, 0)).await;
+ /// sleep(Duration::new(1, 0)).await;
/// let new_now = Instant::now();
/// println!("{:?}", new_now.saturating_duration_since(now));
/// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns
@@ -97,13 +97,13 @@ impl Instant {
/// # Examples
///
/// ```
- /// use tokio::time::{Duration, Instant, delay_for};
+ /// use tokio::time::{Duration, Instant, sleep};
///
/// #[tokio::main]
/// async fn main() {
/// let instant = Instant::now();
/// let three_secs = Duration::from_secs(3);
- /// delay_for(three_secs).await;
+ /// sleep(three_secs).await;
/// assert!(instant.elapsed() >= three_secs);
/// }
/// ```
diff --git a/tokio/src/time/interval.rs b/tokio/src/time/interval.rs
index 52e081ce..5f05b2f9 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::{delay_until, Delay, Duration, Instant};
+use crate::time::{sleep_until, Delay, Duration, Instant};
use std::future::Future;
use std::pin::Pin;
@@ -36,12 +36,12 @@ use std::task::{Context, Poll};
///
/// A simple example using `interval` to execute a task every two seconds.
///
-/// The difference between `interval` and [`delay_for`] is that an `interval`
+/// The difference between `interval` and [`sleep`] is that an `interval`
/// measures the time since the last tick, which means that `.tick().await`
/// may wait for a shorter time than the duration specified for the interval
/// if some time has passed between calls to `.tick().await`.
///
-/// If the tick in the example below was replaced with [`delay_for`], the task
+/// If the tick in the example below was replaced with [`sleep`], the task
/// would only be executed once every three seconds, and not every two
/// seconds.
///
@@ -50,7 +50,7 @@ use std::task::{Context, Poll};
///
/// async fn task_that_takes_a_second() {
/// println!("hello");
-/// time::delay_for(time::Duration::from_secs(1)).await
+/// time::sleep(time::Duration::from_secs(1)).await
/// }
///
/// #[tokio::main]
@@ -63,7 +63,7 @@ use std::task::{Context, Poll};
/// }
/// ```
///
-/// [`delay_for`]: crate::time::delay_for()
+/// [`sleep`]: crate::time::sleep()
pub fn interval(period: Duration) -> Interval {
assert!(period > Duration::new(0, 0), "`period` must be non-zero.");
@@ -101,7 +101,7 @@ pub fn interval_at(start: Instant, period: Duration) -> Interval {
assert!(period > Duration::new(0, 0), "`period` must be non-zero.");
Interval {
- delay: delay_until(start),
+ delay: sleep_until(start),
period,
}
}
diff --git a/tokio/src/time/mod.rs b/tokio/src/time/mod.rs
index 72b0317f..c8c797d9 100644
--- a/tokio/src/time/mod.rs
+++ b/tokio/src/time/mod.rs
@@ -27,14 +27,14 @@
//! Wait 100ms and print "100 ms have elapsed"
//!
//! ```
-//! use tokio::time::delay_for;
+//! use tokio::time::sleep;
//!
//! use std::time::Duration;
//!
//!
//! #[tokio::main]
//! async fn main() {
-//! delay_for(Duration::from_millis(100)).await;
+//! sleep(Duration::from_millis(100)).await;
//! println!("100 ms have elapsed");
//! }
//! ```
@@ -61,12 +61,12 @@
//!
//! A simple example using [`interval`] to execute a task every two seconds.
//!
-//! The difference between [`interval`] and [`delay_for`] is that an
+//! The difference between [`interval`] and [`sleep`] is that an
//! [`interval`] measures the time since the last tick, which means that
//! `.tick().await` may wait for a shorter time than the duration specified
//! for the interval if some time has passed between calls to `.tick().await`.
//!
-//! If the tick in the example below was replaced with [`delay_for`], the task
+//! If the tick in the example below was replaced with [`sleep`], the task
//! would only be executed once every three seconds, and not every two
//! seconds.
//!
@@ -75,7 +75,7 @@
//!
//! async fn task_that_takes_a_second() {
//! println!("hello");
-//! time::delay_for(time::Duration::from_secs(1)).await
+//! time::sleep(time::Duration::from_secs(1)).await
//! }
//!
//! #[tokio::main]
@@ -88,7 +88,7 @@
//! }
//! ```
//!
-//! [`delay_for`]: crate::time::delay_for()
+//! [`sleep`]: crate::time::sleep()
//! [`interval`]: crate::time::interval()
mod clock;
@@ -101,7 +101,7 @@ pub mod delay_queue;
pub use delay_queue::DelayQueue;
mod delay;
-pub use delay::{delay_for, delay_until, Delay};
+pub use delay::{sleep, sleep_until, Delay};
pub(crate) mod driver;
diff --git a/tokio/src/time/tests/mod.rs b/tokio/src/time/tests/mod.rs
index 4710d470..e112b8e1 100644
--- a/tokio/src/time/tests/mod.rs
+++ b/tokio/src/time/tests/mod.rs
@@ -18,5 +18,5 @@ fn registration_is_send_and_sync() {
#[should_panic]
fn delay_is_eager() {
let when = Instant::now() + Duration::from_millis(100);
- let _ = time::delay_until(when);
+ let _ = time::sleep_until(when);
}
diff --git a/tokio/src/time/timeout.rs b/tokio/src/time/timeout.rs
index efc3dc5c..0804f265 100644
--- a/tokio/src/time/timeout.rs
+++ b/tokio/src/time/timeout.rs
@@ -4,7 +4,7 @@
//!
//! [`Timeout`]: struct@Timeout
-use crate::time::{delay_until, Delay, Duration, Instant};
+use crate::time::{sleep_until, Delay, Duration, Instant};
use pin_project_lite::pin_project;
use std::fmt;
@@ -92,7 +92,7 @@ pub fn timeout_at<T>(deadline: Instant, future: T) -> Timeout<T>
where
T: Future,
{
- let delay = delay_until(deadline);
+ let delay = sleep_until(deadline);
Timeout {
value: future,
diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs
index b3492b5e..c82d8a5a 100644
--- a/tokio/tests/async_send_sync.rs
+++ b/tokio/tests/async_send_sync.rs
@@ -243,8 +243,8 @@ async_assert_fn!(tokio::task::LocalSet::run_until(_, BoxFutureSync<()>): !Send &
assert_value!(tokio::task::LocalSet: !Send & !Sync);
async_assert_fn!(tokio::time::advance(Duration): Send & Sync);
-async_assert_fn!(tokio::time::delay_for(Duration): Send & Sync);
-async_assert_fn!(tokio::time::delay_until(Instant): Send & Sync);
+async_assert_fn!(tokio::time::sleep(Duration): Send & Sync);
+async_assert_fn!(tokio::time::sleep_until(Instant): Send & Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFutureSync<()>): Send & Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFuture<()>): !Send & !Sync);
diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs
index a6c8f8f5..f971409b 100644
--- a/tokio/tests/macros_select.rs
+++ b/tokio/tests/macros_select.rs
@@ -359,7 +359,7 @@ async fn join_with_select() {
async fn use_future_in_if_condition() {
use tokio::time::{self, Duration};
- let mut delay = time::delay_for(Duration::from_millis(50));
+ let mut delay = time::sleep(Duration::from_millis(50));
tokio::select! {
_ = &mut delay, if !delay.is_elapsed() => {
@@ -459,7 +459,7 @@ async fn async_noop() {}
async fn async_never() -> ! {
use tokio::time::Duration;
loop {
- tokio::time::delay_for(Duration::from_millis(10)).await;
+ tokio::time::sleep(Duration::from_millis(10)).await;
}
}
diff --git a/tokio/tests/process_issue_2174.rs b/tokio/tests/process_issue_2174.rs
index 4493d54a..6ee7d1ab 100644
--- a/tokio/tests/process_issue_2174.rs
+++ b/tokio/tests/process_issue_2174.rs
@@ -36,7 +36,7 @@ async fn issue_2174() {
});
// Sleep enough time so that the child process's stdin's buffer fills.
- time::delay_for(Duration::from_secs(1)).await;
+ time::sleep(Duration::from_secs(1)).await;
// Kill the child process.
child.kill().await.unwrap();
diff --git a/tokio/tests/process_kill_on_drop.rs b/tokio/tests/process_kill_on_drop.rs
index f376c154..f67bb23c 100644
--- a/tokio/tests/process_kill_on_drop.rs
+++ b/tokio/tests/process_kill_on_drop.rs
@@ -5,7 +5,7 @@ use std::process::Stdio;
use std::time::Duration;
use tokio::io::AsyncReadExt;
use tokio::process::Command;
-use tokio::time::delay_for;
+use tokio::time::sleep;
use tokio_test::assert_ok;
#[tokio::test]
@@ -30,7 +30,7 @@ async fn kill_on_drop() {
.spawn()
.unwrap();
- delay_for(Duration::from_secs(2)).await;
+ sleep(Duration::from_secs(2)).await;
let mut out = child.stdout.take().unwrap();
drop(child);
diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs
index 7f0491c4..3e95c2aa 100644
--- a/tokio/tests/rt_common.rs
+++ b/tokio/tests/rt_common.rs
@@ -437,7 +437,7 @@ rt_test! {
let dur = Duration::from_millis(50);
rt.block_on(async move {
- time::delay_for(dur).await;
+ time::sleep(dur).await;
});
assert!(now.elapsed() >= dur);
@@ -454,7 +454,7 @@ rt_test! {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
- time::delay_for(dur).await;
+ time::sleep(dur).await;
assert_ok!(tx.send(()));
});
@@ -526,7 +526,7 @@ rt_test! {
// use the futures' block_on fn to make sure we aren't setting
// any Tokio context
futures::executor::block_on(async {
- tokio::time::delay_for(dur).await;
+ tokio::time::sleep(dur).await;
});
assert!(now.elapsed() >= dur);
@@ -588,7 +588,7 @@ rt_test! {
let jh1 = thread::spawn(move || {
rt.block_on(async move {
rx2.await.unwrap();
- time::delay_for(Duration::from_millis(5)).await;
+ time::sleep(Duration::from_millis(5)).await;
tx1.send(()).unwrap();
});
});
@@ -596,9 +596,9 @@ rt_test! {
let jh2 = thread::spawn(move || {
rt2.block_on(async move {
tx2.send(()).unwrap();
- time::delay_for(Duration::from_millis(5)).await;
+ time::sleep(Duration::from_millis(5)).await;
rx1.await.unwrap();
- time::delay_for(Duration::from_millis(5)).await;
+ time::sleep(Duration::from_millis(5)).await;
});
});
@@ -850,11 +850,11 @@ rt_test! {
let buf = [0];
loop {
send_half.send_to(&buf, &addr).await.unwrap();
- tokio::time::delay_for(Duration::from_millis(1)).await;
+ tokio::time::sleep(Duration::from_millis(1)).await;
}
});
- tokio::time::delay_for(Duration::from_millis(5)).await;
+ tokio::time::sleep(Duration::from_millis(5)).await;
});
}
}
@@ -881,7 +881,7 @@ rt_test! {
let runtime = rt();
runtime.block_on(async move {
- tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
+ tokio::time::sleep(std::time::Duration::from_millis(100)).await;
});
Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_secs(10_000));
@@ -1006,7 +1006,7 @@ rt_test! {
}).collect::<Vec<_>>();
// Hope that all the tasks complete...
- time::delay_for(Duration::from_millis(100)).await;
+ time::sleep(Duration::from_millis(100)).await;
poll_fn(|cx| {
// At least one task should not be ready
diff --git a/tokio/tests/stream_timeout.rs b/tokio/tests/stream_timeout.rs
index f65c8351..698c1d39 100644
--- a/tokio/tests/stream_timeout.rs
+++ b/tokio/tests/stream_timeout.rs
@@ -1,14 +1,14 @@
#![cfg(feature = "full")]
use tokio::stream::{self, StreamExt};
-use tokio::time::{self, delay_for, Duration};
+use tokio::time::{self, sleep, Duration};
use tokio_test::*;
use futures::StreamExt as _;
async fn maybe_delay(idx: i32) -> i32 {
if idx % 2 == 0 {
- delay_for(ms(200)).await;
+ sleep(ms(200)).await;
}
idx
}
diff --git a/tokio/tests/task_local.rs b/tokio/tests/task_local.rs
index 7f508997..58b58183 100644
--- a/tokio/tests/task_local.rs
+++ b/tokio/tests/task_local.rs
@@ -16,7 +16,7 @@ async fn local() {
assert_eq!(*v, 2);
});
- tokio::time::delay_for(std::time::Duration::from_millis(10)).await;
+ tokio::time::sleep(std::time::Duration::from_millis(10)).await;
assert_eq!(REQ_ID.get(), 2);
}));
diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs
index 23e92586..1dc779ce 100644
--- a/tokio/tests/task_local_set.rs
+++ b/tokio/tests/task_local_set.rs
@@ -62,11 +62,11 @@ async fn localset_future_timers() {
let local = LocalSet::new();
local.spawn_local(async move {
- time::delay_for(Duration::from_millis(10)).await;
+ time::sleep(Duration::from_millis(10)).await;
RAN1.store(true, Ordering::SeqCst);
});
local.spawn_local(async move {
- time::delay_for(Duration::from_millis(20)).await;
+ time::sleep(Duration::from_millis(20)).await;
RAN2.store(true, Ordering::SeqCst);
});
local.await;
@@ -114,7 +114,7 @@ async fn local_threadpool_timer() {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = task::spawn_local(async move {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
- time::delay_for(Duration::from_millis(10)).await;
+ time::sleep(Duration::from_millis(10)).await;
assert!(ON_RT_THREAD.with(|cell| cell.get()));
});
join.await.unwrap();
@@ -299,7 +299,7 @@ fn drop_cancels_tasks() {
started_tx.send(()).unwrap();
loop {
- time::delay_for(Duration::from_secs(3600)).await;
+ time::sleep(Duration::from_secs(3600)).await;
}
});
@@ -367,7 +367,7 @@ fn drop_cancels_remote_tasks() {
let local = LocalSet::new();
local.spawn_local(async move { while rx.recv().await.is_some() {} });
loca