DelayController

interface DelayController

Control the virtual clock time of a CoroutineDispatcher.

Testing libraries may expose this interface to the tests instead of TestCoroutineDispatcher.

This interface is deprecated without replacement. Instead, TestCoroutineScheduler is supposed to be used to control the virtual time. Please see the migration guide for an instruction on how to update the code for the new API.

Functions

advanceTimeBy
Link copied to clipboard
abstract fun advanceTimeBy(delayTimeMillis: Long): Long

Moves the Dispatcher's virtual clock forward by a specified amount of time.

advanceUntilIdle
Link copied to clipboard
abstract fun advanceUntilIdle(): Long

Immediately execute all pending tasks and advance the virtual clock-time to the last delay.

cleanupTestCoroutines
Link copied to clipboard
abstract fun cleanupTestCoroutines()

Call after test code completes to ensure that the dispatcher is properly cleaned up.

pauseDispatcher
Link copied to clipboard
abstract fun pauseDispatcher()

Pause the dispatcher.

abstract suspend fun pauseDispatcher(block: suspend () -> Unit)

Run a block of code in a paused dispatcher.

resumeDispatcher
Link copied to clipboard
abstract fun resumeDispatcher()

Resume the dispatcher from a paused state.

runCurrent
Link copied to clipboard
abstract fun runCurrent()

Run any tasks that are pending at or before the current virtual clock-time.

Properties

currentTime
Link copied to clipboard
abstract val currentTime: Long

Returns the current virtual clock-time as it is known to this Dispatcher.