Skip to content

Commit

Permalink
fix: Update the docs of "pause" to state that time will still advance (
Browse files Browse the repository at this point in the history
…#2647)

* doc: Update the docs of "pause" to state that time will still advance

This was changed in #2059. This had me extremely confused for some time
as my timeouts fired immediately, without the wrapped future that were
waiting on IO to actually run long enough.

I am not sure about the exact wording here but this had me very confused
for some time. Deprecating "pause" and giving it a more accurate name
may be a good idea as well.

```rust
async fn timeout_advances() {
    time::pause();

    timeout(ms(1), async {
        // Change to 1 and the this future resolve, 2 or
        // more and the timeout resolves
        for _ in 0..2 {
            tokio::task::yield_now().await
        }
    })
    .await
    .unwrap();
}

```

* Update tokio/src/time/clock.rs

Co-authored-by: Alice Ryhl <alice@ryhl.io>

Co-authored-by: Alice Ryhl <alice@ryhl.io>
  • Loading branch information
Marwes and Darksonn authored Jul 10, 2020
1 parent 2aa8751 commit f69e5bf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tokio/src/time/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ cfg_test_util! {
/// Pause time
///
/// The current value of `Instant::now()` is saved and all subsequent calls
/// to `Instant::now()` will return the saved value. This is useful for
/// running tests that are dependent on time.
/// to `Instant::now()` until the timer wheel is checked again will return the saved value.
/// Once the timer wheel is checked, time will immediately advance to the next registered
/// `Delay`. This is useful for running tests that depend on time.
///
/// # Panics
///
Expand Down

0 comments on commit f69e5bf

Please sign in to comment.