diff options
author | Juan Alvarez <j@yabit.io> | 2020-10-01 02:24:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 09:24:33 +0200 |
commit | 53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5 (patch) | |
tree | 66f0b4c089729616b57bbb69b0a6351b45a0c898 /tokio/src/time/delay.rs | |
parent | 971ed2c6df9cb3bf3543a9c780662a0b4d1a8d40 (diff) |
time: introduce `sleep` and `sleep_until` functions (#2826)
Diffstat (limited to 'tokio/src/time/delay.rs')
-rw-r--r-- | tokio/src/time/delay.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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. // |