Skip to content

Commit

Permalink
time: document auto-advancing behavior of runtime (#3763)
Browse files Browse the repository at this point in the history
  • Loading branch information
eb-64-64 authored Jun 16, 2021
1 parent 60bd40d commit 5ad3dd3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tokio/src/time/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ cfg_test_util! {
///
/// Panics if time is already frozen or if called from outside of a
/// `current_thread` Tokio runtime.
///
/// # Auto-advance
///
/// If time is paused and the runtime has no work to do, the clock is
/// auto-advanced to the next pending timer. This means that [`Sleep`] or
/// other timer-backed primitives can cause the runtime to advance the
/// current time when awaited.
///
/// [`Sleep`]: crate::time::Sleep
pub fn pause() {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.pause();
Expand Down Expand Up @@ -111,6 +120,12 @@ cfg_test_util! {
///
/// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
///
/// # Auto-advance
///
/// If the time is paused and there is no work to do, the runtime advances
/// time to the next timer. See [`pause`](pause#auto-advance) for more
/// details.
pub async fn advance(duration: Duration) {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.advance(duration);
Expand Down

0 comments on commit 5ad3dd3

Please sign in to comment.