Skip to content

Instantly share code, notes, and snippets.

@arkilis
Last active January 18, 2023 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkilis/6cdd2d4ad1d30e5852cd1a46210833e0 to your computer and use it in GitHub Desktop.
Save arkilis/6cdd2d4ad1d30e5852cd1a46210833e0 to your computer and use it in GitHub Desktop.
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