Skip to content

Instantly share code, notes, and snippets.

@arkilis
Last active January 18, 2023 05:42
Embed
What would you like to do?
Use launch to create coroutines in Kotlin. Full article: https://needone.app/introduction-to-coroutine-in-kotlin/
// Use launch to create coroutines
// https://needone.app/introduction-to-coroutine-in-kotlin/
import kotlinx.coroutines.*
fun main() {
// Start a coroutine using the launch function
val job = GlobalScope.launch {
// Perform a long-running task in the background
delay(1000L)
println("Hello, world!")
}
// Wait for the coroutine to finish
runBlocking {
job.join()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment