Coroutines Builders: The launch Builder
Learn about the launch coroutine builder of the kotlinx.coroutines library.
We'll cover the following...
We'll cover the following...
The launch builder
Conceptually, the launch works similarly to starting a new thread (thread function). We start a coroutine, which will run independently, like a firework launched into the air. This is how we use launch—to start a process.
fun main() {
GlobalScope.launch {
delay(1000L)
println("World 1!")
}
GlobalScope.launch {
delay(1000L)
println("World 2!")
}
GlobalScope.launch {
delay(1000L)
println("World 3!")
}
println("Hello,")
Thread.sleep(2000L)
}launch Builder as a thread
The launch function is an extension function on the CoroutineScope interface. This is part of a vital mechanism called ...