mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
time: introduce sleep and sleep_until functions (#2826)
This commit is contained in:
@@ -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>;
|
||||
|
||||
@@ -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();
|
||||
/// });
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user