Hello I’m trying to have a constant flow for a `ui...
# coroutines
r
Hello I’m trying to have a constant flow for a
uiState
in compose. With a list of product, and listen on execution of those product and update the UI in consequence.
Copy code
private fun StateFlow<List<Product>>.toItems(): Flow<List<HomeItem>> {
    return map { products -> ... }
        .transformLatest { products ->
            if (products.isEmpty()) {
                emit(emptyList())
            } else {
                combine(
                    products.filter(Product::isNotEmpty)
                        .map { product ->
                            combine(
                                product.refreshObs.asFlow(),
                                executionStateOf(product.id)
                                    .onStart { println("FlowTest Execution onStart") }
                                    .onCompletion { println("FlowTest Execution onCompletion") }
                                    .onEach { println("FlowTest Execution onEach") }
                            ) { _, data ->
                                println("FlowTest Combine result")
                                product.toItem(data)
                            }
                                .scan(product.toItem(Data.Empty)) { _, item ->
                                    item
                                }
                        },
                    Array<HomeItem>::toList
                )
                    .collect {
                        emit(it)
                    }
            }
        }
}
But the
executionStateOf
is cancelled with
child of the scoped flow was cancelled
executionStateOf
is a MutableSharedFlow
l
I've recently had this issue when doing nested combines, don't know for sure why. You should try to simplify your logic. what worked for me was just having one combine level. Also the collection point could be the issue. It should be possible to just map the data from
List<Product>
to
List<HomeItem>
using only operators. I noticed when I tried collecting and updating some other flow, my nested combine went inactive and therefore cancelled.
r
Thank’s I simplified a lot. And the main problem was overriding the get instead of affecting the variable directly.