Sobes.tech
Back to tasks
Junior — Senior
38

Поведение runBlocking при работе с async‑корутинами

Companies where asked:

amoCRMamoCRM
Get help with live coding in real time with Sobes Copilot
Task condition

Определите, какой вывод появится в консоли после выполнения следующей программы:

val coroutineContext = Job() + Dispatchers.Default
val mainScope = CoroutineScope(coroutineContext)

val first = mainScope.async {
    println(1)
    delay(400)
    "First Async"
}

val second = mainScope.async {
    println(2)
    delay(100)
    "Second Async"
}

runBlocking {
    delay(300)
    println(3)
    println("${first.await()} ${second.await()}")
}