Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7167e9d

Browse files
committedJun 5, 2019
initial docs
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 25b7002 commit 7167e9d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
 

‎src/time.rs

+49
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,67 @@ pub use interval::Interval;
6161
use std::time::{Duration, Instant};
6262

6363
/// Sleep the current future for the given duration.
64+
///
65+
/// ## Examples
66+
/// ```
67+
/// # #![feature(async_await)]
68+
/// use runtime::time::delay_for;
69+
/// use std::time::{Duration, Instant};
70+
///
71+
/// # #[runtime::main]
72+
/// # async fn main () -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
73+
/// let start = Instant::now();
74+
/// let now = delay_for(Duration::from_millis(20)).await;
75+
///
76+
/// assert!(now - start >= Duration::from_millis(20));
77+
/// # Ok(())}
78+
/// ```
6479
#[inline]
6580
pub fn delay_for(dur: Duration) -> Delay {
6681
Delay::new(dur)
6782
}
6883

6984
/// Sleep the current future until the given time.
85+
///
86+
/// ## Examples
87+
/// ```
88+
/// # #![feature(async_await)]
89+
/// use runtime::time::delay_until;
90+
/// use std::time::{Duration, Instant};
91+
///
92+
/// # #[runtime::main]
93+
/// # async fn main () -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
94+
/// let start = Instant::now();
95+
/// let now = delay_until(start + Duration::from_millis(40)).await;
96+
///
97+
/// assert!(now - start >= Duration::from_millis(40));
98+
/// # Ok(())}
99+
/// ```
70100
#[inline]
71101
pub fn delay_until(at: Instant) -> Delay {
72102
Delay::new_at(at)
73103
}
74104

75105
/// Create a stream that fires events at a set interval.
106+
///
107+
/// ## Examples
108+
/// ```
109+
/// # #![feature(async_await)]
110+
/// # use futures::prelude::*;
111+
/// use runtime::time::interval;
112+
/// use std::time::{Duration, Instant};
113+
///
114+
/// # #[runtime::main]
115+
/// # async fn main () -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
116+
/// let start = Instant::now();
117+
/// let mut interval = interval(Duration::from_millis(10)).take(3);
118+
/// while let Some(now) = interval.next().await {
119+
/// println!("{}ms have elapsed", (now - start).as_millis());
120+
/// }
121+
///
122+
/// assert!(Instant::now() - start >= Duration::from_millis(30));
123+
/// # Ok(())}
124+
/// ```
76125
#[inline]
77126
pub fn interval(dur: Duration) -> Interval {
78127
Interval::new(dur)

0 commit comments

Comments
 (0)
This repository has been archived.