Last active
April 24, 2021 14:56
-
-
Save ferazog/4a52fbed0d525d273ba1331b2256f09b to your computer and use it in GitHub Desktop.
Start with coroutines
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
fun ejecutarCoroutine() { | |
println("iniciando coroutine") | |
GlobalScope.launch { | |
/* | |
launch es una extensión que permite ejecutar una coroutine, | |
en este caso dentro del scope GlobalScope | |
*/ | |
println("hola mundo desde una coroutine") | |
} | |
Thread.sleep(1_000) // El sleep permite una brecha de tiempo para que la coroutine termine su trabajo | |
println("fin de la app") | |
} | |
/* | |
Resultado esperado: | |
iniciando coroutine | |
hola mundo desde una coroutine | |
fin de la app | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment