Skip to content

Instantly share code, notes, and snippets.

@wellingtoncosta
Last active February 25, 2019 13:46
Show Gist options
  • Save wellingtoncosta/bea3d3f6244f2b287b409997b8a73716 to your computer and use it in GitHub Desktop.
Save wellingtoncosta/bea3d3f6244f2b287b409997b8a73716 to your computer and use it in GitHub Desktop.
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