doc: sync interval.rs and time/mod.rs docs (#3533)

This commit is contained in:
Marko Mikulicic
2021-02-22 11:45:49 +01:00
committed by GitHub
parent 52457dcf5b
commit 7de18af82c
+6 -8
View File
@@ -56,10 +56,10 @@
//! //!
//! A simple example using [`interval`] to execute a task every two seconds. //! A simple example using [`interval`] to execute a task every two seconds.
//! //!
//! The difference between [`interval`] and [`sleep`] is that an //! The difference between [`interval`] and [`sleep`] is that an [`interval`]
//! [`interval`] measures the time since the last tick, which means that //! measures the time since the last tick, which means that `.tick().await`
//! `.tick().await` may wait for a shorter time than the duration specified //! may wait for a shorter time than the duration specified for the interval
//! for the interval if some time has passed between calls to `.tick().await`. //! if some time has passed between calls to `.tick().await`.
//! //!
//! If the tick in the example below was replaced with [`sleep`], the task //! 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 //! would only be executed once every three seconds, and not every two
@@ -75,11 +75,9 @@
//! //!
//! #[tokio::main] //! #[tokio::main]
//! async fn main() { //! async fn main() {
//! let interval = time::interval(time::Duration::from_secs(2)); //! let mut interval = time::interval(time::Duration::from_secs(2));
//! tokio::pin!(interval);
//!
//! for _i in 0..5 { //! for _i in 0..5 {
//! interval.as_mut().tick().await; //! interval.tick().await;
//! task_that_takes_a_second().await; //! task_that_takes_a_second().await;
//! } //! }
//! } //! }