Skip to content

Suiteopensavvy.prepared.suiteadvanceUntilIdle

advanceUntilIdle


Runs all enqueued tasks in the specified order, advancing the virtual time as needed until there are no more scheduled tasks.

This is similar to `delay(Long.MAX_VALUE)`, except it leaves the virtual time on whenever the last task was scheduled.

Example

test("Execute subtasks") {
    launch {
        delay(1000)
        println("A")

        launch {
            delay(3000)
            println("B")
        }
    }

    launch {
        delay(2000)
        println("C")
    }

    time.advanceUntilIdle()
    assertEquals(4000, time.nowMillis)
}

Background tasks

This method advances time until all the last foreground tasks's scheduled time. There may be background tasks that are scheduled for later.

Stability warning

The KotlinX.Coroutines team is considering removing this functionality. Learn more in #3919.