kotlinx.coroutines
kotlinx.coroutines copied to clipboard
docs: add example for `runTest` to reiterate that runTest waits for children to finish
trafficstars
Two previous examples (L63-84) could be misinterpreted as if there's a need to explicitly join or generally wait for children coroutines to finish, since they don't do anything after joining the launched coroutine.
The misleading examples (L63-84):
* @Test
* fun exampleWaitingForAsyncTasks1() = runTest {
* // 1
* val job = launch {
* // 3
* }
* // 2
* job.join() // the main test coroutine suspends here, so the child is executed
* // 4
* }
*
* @Test
* fun exampleWaitingForAsyncTasks2() = runTest {
* // 1
* launch {
* // 3
* }
* // 2
* testScheduler.advanceUntilIdle() // runs the tasks until their queue is empty
* // 4
* }
* ```