Function tokio::time::pause[][src]

pub fn pause()
This is supported on crate features time and test-util only.
Expand description

Pause time

The current value of Instant::now() is saved and all subsequent calls 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 Sleep. This is useful for running tests that depend on time.

Pausing time requires the current_thread Tokio runtime. This is the default runtime used by #[tokio::test]. The runtime can be initialized with time in a paused state using the Builder::start_paused method.

Panics

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.