Skip to content

Commit

Permalink
doc: Sync interval.rs and time/mod.rs docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkmik committed Feb 18, 2021
1 parent 6fd06aa commit a09f205
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions tokio/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,33 @@
//! # }
//! ```
//!
//! A simple example using [`interval`] to execute a task every two seconds.
//!
//! The difference between [`interval`] and [`sleep`] is that an
//! [`interval`] measures the time since the last tick, which means that
//! `.tick().await` may wait for a shorter time than the duration specified
//! for the interval if some time has passed between calls to `.tick().await`.
//!
//! If the tick in the example below was replaced with [`sleep`], the task
//! would only be executed once every three seconds, and not every two
//! seconds.
//!
//! ```
//! use tokio::time;
//!
//! async fn task_that_takes_a_second() {
//! println!("hello");
//! time::sleep(time::Duration::from_secs(1)).await
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! let interval = time::interval(time::Duration::from_secs(2));
//! tokio::pin!(interval);
//!
//! for _i in 0..5 {
//! interval.as_mut().tick().await;
//! task_that_takes_a_second().await;
//! }
//! }
/// A simple example using `interval` to execute a task every two seconds.
///
/// The difference between `interval` and [`sleep`] is that an `interval`
/// measures the time since the last tick, which means that `.tick().await`
/// may wait for a shorter time than the duration specified for the interval
/// if some time has passed between calls to `.tick().await`.
///
/// If the tick in the example below was replaced with [`sleep`], the task
/// would only be executed once every three seconds, and not every two
/// seconds.
///
/// ```
/// use tokio::time;
///
/// async fn task_that_takes_a_second() {
/// println!("hello");
/// time::sleep(time::Duration::from_secs(1)).await
/// }
///
/// #[tokio::main]
/// async fn main() {
/// let mut interval = time::interval(time::Duration::from_secs(2));
/// for _i in 0..5 {
/// interval.tick().await;
/// task_that_takes_a_second().await;
/// }
/// }
//! ```
//!
//! [`sleep`]: crate::time::sleep()
Expand Down

0 comments on commit a09f205

Please sign in to comment.