Skip to content

Instantly share code, notes, and snippets.

@ferazog
Created April 24, 2021 20: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 ferazog/83ae70bb44c5ba48465de1b53e2937b5 to your computer and use it in GitHub Desktop.
Save ferazog/83ae70bb44c5ba48465de1b53e2937b5 to your computer and use it in GitHub Desktop.
fun ejecutarCoroutine() {
GlobalScope.launch() {
val user = obtenerUsuarioDesdeRed()
}
Thread.sleep(1_000)
}
// Retorna un Usuario modelado es este ejemplo por un String
suspend fun obtenerUsuarioDesdeRed(): String { // Usa la palabra clave suspend para soportar funciones suspendidas
delay(500) // La función delay es soportada, en caso contrario se mostraría un error en tiempo de codificación
return "Felipe"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment