Hi, does anyone know why launching many concurrent...
# javascript
l
Hi, does anyone know why launching many concurrent operations/api calls with coroutines would be 3x-4x slower in firefox vs chrome? something along the lines of this:
Copy code
coroutineScope {
    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)
s
As far I see it you are sending your requests subsequently (not concurrently). It seems you need something like
api.getPurchasePriceAsync(item.id)
that returns
Async<T>
or
Promise<T>
and you need to
.await()
them all after
forEachIndexed
or
mapIndexed
at once.
There is also awaitAll helper for such tasks.
l
That’s not the issue. It is being launched concurrently. launch does not block @Sergei Grishchenko
👌 1