Sobes.tech
Junior — Senior

How async‑coroutine execution and synchronization occur

livecode

Task condition

Determine what text will appear in the console after running the following code snippet.

val coroutineContext = Job() + Dispatchers.IO

val mainScope = CoroutineScope(coroutineContext)

mainScope.launch {
    val deferred1 = async {
        delay(1000)
        "1"
    }

    val deferred2 = async {
        delay(500)
        "2"
    }

    deferred1.join()
    println(deferred2.await())
}