Search⌘ K

Solution: Job and Awaiting Children

Explore how to effectively manage Kotlin coroutine jobs and synchronize their execution by using the join method. This lesson helps you understand parent-child coroutine relationships and ensures proper completion handling in your code.

We'll cover the following...

Solution

The solution to the challenge we just solved is as follows.

fun main(): Unit = runBlocking {
    val job1 = launch {
       delay(1000)
       println("Educative")
   }
   val job2 = launch {
       delay(2000)
       println("Inc.")
   }

   job1.join()
   job2.join()
   println("Completed")
}
Solution of the challenge

Explanation

Here is a line–by–line ...