From 2463d85bb2c093bd471fb2169efacba9c2fae5bf Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sat, 14 Aug 2021 09:54:45 +0200 Subject: [PATCH 1/2] time: make Sleep examples easier to find --- tokio/src/time/driver/sleep.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tokio/src/time/driver/sleep.rs b/tokio/src/time/driver/sleep.rs index 40f745ad7e8..cfa3b331a2b 100644 --- a/tokio/src/time/driver/sleep.rs +++ b/tokio/src/time/driver/sleep.rs @@ -12,10 +12,31 @@ use std::task::{self, Poll}; /// operates at millisecond granularity and should not be used for tasks that /// require high-resolution timers. /// +/// To run something regularly on a schedule, see [`interval`]. +/// /// # Cancellation /// /// Canceling a sleep instance is done by dropping the returned future. No additional /// cleanup work is required. +/// +/// # Examples +/// +/// Wait 100ms and print "100 ms have elapsed". +/// +/// ``` +/// use tokio::time::{sleep, Instant, Duration}; +/// +/// #[tokio::main] +/// async fn main() { +/// sleep_until(Instant::now() + Duration::from_millis(100)).await; +/// println!("100 ms have elapsed"); +/// } +/// ``` +/// +/// See the documentation for the [`Sleep`] type for more examples. +/// +/// [`Sleep`]: struct@crate::time::Sleep +/// [`interval`]: crate::time::interval() // Alias for old name in 0.x #[cfg_attr(docsrs, doc(alias = "delay_until"))] pub fn sleep_until(deadline: Instant) -> Sleep { @@ -54,6 +75,9 @@ pub fn sleep_until(deadline: Instant) -> Sleep { /// } /// ``` /// +/// See the documentation for the [`Sleep`] type for more examples. +/// +/// [`Sleep`]: struct@crate::time::Sleep /// [`interval`]: crate::time::interval() // Alias for old name in 0.x #[cfg_attr(docsrs, doc(alias = "delay_for"))] @@ -216,6 +240,8 @@ impl Sleep { /// # } /// ``` /// + /// See also the top-level examples. + /// /// [`Pin::as_mut`]: fn@std::pin::Pin::as_mut pub fn reset(self: Pin<&mut Self>, deadline: Instant) { let me = self.project(); From 6f32ca14744ecc94293deea9c31fcd435069f312 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sat, 14 Aug 2021 21:26:21 +0200 Subject: [PATCH 2/2] Update tokio/src/time/driver/sleep.rs --- tokio/src/time/driver/sleep.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/time/driver/sleep.rs b/tokio/src/time/driver/sleep.rs index cfa3b331a2b..4e9ed65d4b3 100644 --- a/tokio/src/time/driver/sleep.rs +++ b/tokio/src/time/driver/sleep.rs @@ -24,7 +24,7 @@ use std::task::{self, Poll}; /// Wait 100ms and print "100 ms have elapsed". /// /// ``` -/// use tokio::time::{sleep, Instant, Duration}; +/// use tokio::time::{sleep_until, Instant, Duration}; /// /// #[tokio::main] /// async fn main() {