Last active
January 18, 2023 05:42
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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