Skip to content

Instantly share code, notes, and snippets.

@ferazog
Created April 24, 2021 20:07
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 ferazog/1306ead0260f8e65c69e7e142bc183cf to your computer and use it in GitHub Desktop.
Save ferazog/1306ead0260f8e65c69e7e142bc183cf to your computer and use it in GitHub Desktop.
fun ejecutarCoroutine() {
val jobPadre = GlobalScope.launch {
while(isActive) {
println("hola desde la coroutine padre")
}
}
GlobalScope.launch(jobPadre) { // Pasando a la coroutine la referencia al job padre
while(isActive) {
println("hola desde la coroutine hija")
}
}
Thread.sleep(1_000)
jobPadre.cancel() // Cancela la coroutine padre e hija
println("fin de la app")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment