Created
March 21, 2019 14:35
-
-
Save MovileGente/2faa5c3b3945409d2a83d09b1fc08af9 to your computer and use it in GitHub Desktop.
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
suspend fun queryUser(id: Int): User { | |
delay(500) // simulando latência de rede ou outra operação lenta | |
return User(id = id, name = "gente.firme", email = "talentos@movile.com", phone = 5511000000000L) | |
} | |
suspend fun sendEmail(destination: String, body: String): Boolean { | |
println("Sending email to $destination with body: $body") | |
delay(1000) // simulando um request/operação lenta | |
val couldSentEmail = Random().nextBoolean() | |
if (couldSentEmail) { | |
println("Successfully sent email!") | |
} else { | |
println("Uh, something went terribly wrong") | |
} | |
return couldSentEmail | |
} | |
suspend fun sendSMS(destination: Long, message: String): Boolean { | |
println("Sending sms to $destination with message: $message") | |
delay(500) // simulando um request/operação lenta | |
println("Successfully sent SMS!") | |
return true | |
} | |
suspend fun sendMessageToUser(userId: Int, message: String) { | |
val user = queryUser(userId) | |
val emailStatus = sendEmail(user.email, message) | |
if (!emailStatus) { | |
sendSMS(user.phone, message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment