Luca
12/05/2022, 5:01 AMcoroutineScope {
storeListItems.forEachIndexed { i, item ->
launch(Dispatchers.Default) {
val price = api.getPurchasePrice(item.id)
storeListItems[i] = StoreListItem(item, price)
stateManager.updateScreen(StoreListState::class) {
it.copy(
storeListItems = storeListItems,
)
}
}
}
}
where I have to fetch the prices of many store items with a separate api call for each store item by their id.
Additionally, chrome will update the screen as I expect (the order in which the prices get updated happens progressively) while firefox doesn’t seem to be handling the concurrency correctly and it updates the screen all at once)Sergei Grishchenko
12/05/2022, 8:38 AMapi.getPurchasePriceAsync(item.id)
that returns Async<T>
or Promise<T>
and you need to .await()
them all after forEachIndexed
or mapIndexed
at once.Sergei Grishchenko
12/05/2022, 8:39 AMLuca
12/07/2022, 7:32 AM