5.5.2 Implementation of Coroutines
Implementation of Coroutines
val job = GlobalScope.launch {
delay(1000L)
println("World!")
}
println("Hello,")
job.join() // waits until the job is completed before it outputs
// Output:
// Hello,
// World fun main() = runBlocking { // Creates coroutine scope A
launch { // Creates coroutine scope B
delay(200L)
println("Task from runBlocking")
}
coroutineScope { // Creates a coroutine scope C
launch { // Creates a coroutine scope D
delay(500L)
println("Task from nested launch")
}
delay(100L)
println("Task from coroutine scope")
}
println("Coroutine scope is over")
}
// Output:
// Task from coroutine scope
// Task from runBlocking
// Task from nested launch
// Coroutine scope is overImplementation with Suspending Functions
Last updated
Was this helpful?