kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

docs: add example for `runTest` to reiterate that runTest waits for children to finish

Open murfel opened this issue 7 months ago • 0 comments
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
 * }
 * ```

murfel avatar Apr 21 '25 17:04 murfel