DelayController

@ExperimentalCoroutinesApi interface DelayController

Control the virtual clock time of a CoroutineDispatcher.

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

Properties

currentTime

abstract val currentTime: Long

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

Functions

advanceTimeBy

abstract fun advanceTimeBy(delayTimeMillis: Long): Long

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

advanceUntilIdle

abstract fun advanceUntilIdle(): Long

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

cleanupTestCoroutines

abstract fun cleanupTestCoroutines(): Unit

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

pauseDispatcher

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

Run a block of code in a paused dispatcher.

abstract fun pauseDispatcher(): Unit

Pause the dispatcher.

resumeDispatcher

abstract fun resumeDispatcher(): Unit

Resume the dispatcher from a paused state.

runCurrent

abstract fun runCurrent(): Unit

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

Inheritors

TestCoroutineDispatcher

class TestCoroutineDispatcher : 
    CoroutineDispatcher,
    Delay,
    DelayController

CoroutineDispatcher that performs both immediate and lazy execution of coroutines in tests and implements DelayController to control its virtual clock.

TestCoroutineScope

interface TestCoroutineScope : 
    CoroutineScope,
    UncaughtExceptionCaptor,
    DelayController

A scope which provides detailed control over the execution of coroutines for tests.