summaryrefslogtreecommitdiffstats
path: root/tokio-util
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-util
parent971ed2c6df9cb3bf3543a9c780662a0b4d1a8d40 (diff)
time: introduce `sleep` and `sleep_until` functions (#2826)
Diffstat (limited to 'tokio-util')
-rw-r--r--tokio-util/src/context.rs6
-rw-r--r--tokio-util/src/sync/cancellation_token.rs8
-rw-r--r--tokio-util/tests/context.rs2
3 files changed, 8 insertions, 8 deletions
diff --git a/tokio-util/src/context.rs b/tokio-util/src/context.rs
index e07538d9..5f6c6b9b 100644
--- a/tokio-util/src/context.rs
+++ b/tokio-util/src/context.rs
@@ -46,7 +46,7 @@ pub trait RuntimeExt {
///
/// ```no_run
/// use tokio_util::context::RuntimeExt;
- /// use tokio::time::{delay_for, Duration};
+ /// use tokio::time::{sleep, Duration};
///
/// let rt = tokio::runtime::Builder::new()
/// .threaded_scheduler()
@@ -57,11 +57,11 @@ pub trait RuntimeExt {
/// .threaded_scheduler()
/// .build().unwrap();
///
- /// let fut = delay_for(Duration::from_millis(2));
+ /// let fut = sleep(Duration::from_millis(2));
///
/// rt.block_on(
/// rt2
- /// .wrap(async { delay_for(Duration::from_millis(2)).await }),
+ /// .wrap(async { sleep(Duration::from_millis(2)).await }),
/// );
///```
fn wrap<F: Future>(&self, fut: F) -> TokioContext<'_, F>;
diff --git a/tokio-util/src/sync/cancellation_token.rs b/tokio-util/src/sync/cancellation_token.rs
index baab5ce2..1f29e34a 100644
--- a/tokio-util/src/sync/cancellation_token.rs
+++ b/tokio-util/src/sync/cancellation_token.rs
@@ -37,14 +37,14 @@ use core::task::{Context, Poll, Waker};
/// // The token was cancelled
/// 5
/// }
-/// _ = tokio::time::delay_for(std::time::Duration::from_secs(9999)) => {
+/// _ = tokio::time::sleep(std::time::Duration::from_secs(9999)) => {
/// 99
/// }
/// }
/// });
///
/// tokio::spawn(async move {
-/// tokio::time::delay_for(std::time::Duration::from_millis(10)).await;
+/// tokio::time::sleep(std::time::Duration::from_millis(10)).await;
/// token.cancel();
/// });
///
@@ -185,14 +185,14 @@ impl CancellationToken {
/// // The token was cancelled
/// 5
/// }
- /// _ = tokio::time::delay_for(std::time::Duration::from_secs(9999)) => {
+ /// _ = tokio::time::sleep(std::time::Duration::from_secs(9999)) => {
/// 99
/// }
/// }
/// });
///
/// tokio::spawn(async move {
- /// tokio::time::delay_for(std::time::Duration::from_millis(10)).await;
+ /// tokio::time::sleep(std::time::Duration::from_millis(10)).await;
/// token.cancel();
/// });
///
diff --git a/tokio-util/tests/context.rs b/tokio-util/tests/context.rs
index 2e39b144..ee519130 100644
--- a/tokio-util/tests/context.rs
+++ b/tokio-util/tests/context.rs
@@ -21,5 +21,5 @@ fn tokio_context_with_another_runtime() {
// Without the `HandleExt.wrap()` there would be a panic because there is
// no timer running, since it would be referencing runtime r1.
- let _ = rt1.block_on(rt2.wrap(async move { delay_for(Duration::from_millis(2)).await }));
+ let _ = rt1.block_on(rt2.wrap(async move { sleep(Duration::from_millis(2)).await }));
}