Last active
February 25, 2019 13:46
-
-
Save wellingtoncosta/bea3d3f6244f2b287b409997b8a73716 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
fun main() { | |
GlobalScope.launch { | |
val orders = fetchOrders().await() | |
println(orders) | |
} | |
} | |
suspend fun fetchOrders() = GlobalScope.async { | |
delay(2000) // simulates a external data fetch | |
listOf( | |
Order( | |
id = 1, items = listOf( | |
OrderItem(id = 1, name = "foo", price = 100.0), | |
OrderItem(id = 2, name = "bar", price = 150.0) | |
) | |
), | |
Order( | |
id = 2, items = listOf( | |
OrderItem(id = 3, name = "lorem", price = 200.0), | |
OrderItem(id = 4, name = "ipsum", price = 250.0) | |
) | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment