Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created October 10, 2018 18:57
Show Gist options
  • Save mayojava/448daa211bd8985f15ff6b025ba21a7a to your computer and use it in GitHub Desktop.
Save mayojava/448daa211bd8985f15ff6b025ba21a7a to your computer and use it in GitHub Desktop.
coroutine implementation of fetch user orders snippet
fun showUserOrders(username: String, password: String) = GlobalScope.launch(Dispatchers.Main) {
val user = withContext(Dispatchers.Default) { login(username, password) }
val orders = withContext(Dispatchers.Default) { fetchUserOrders(user.userId) }
showUserOrders(orders)
}
suspend fun login(username: String, password: String) { }
suspend fun fetchUserOrders(userId: Long) { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment