Hi everyone, I have a problem with a List<Flow&...
# flow
j
Hi everyone, I have a problem with a List<Flow<Boolean>> and flattenMerge() of these flows when one of them ends. I will tell you in more detail. I have a function where I launch multiple requests to an API. When the requests are ending they are emitting the results. Up to this point this example works fine, requests are fired in parallel and emit their results. The problem occurs when one of these flows ends cancels the rest of flows that are making requests. Has anybody had a similar problem?
Copy code
fun getData(): Flow<Boolean> {
	var validIds: List<Long> = getIdsForRequest()
	return validIds.chunked(MAX_PIDS).asFlow().map { sublist ->
           		makeRequest(sublist)
        	}.flattenMerge()
}

fun makeRequest(ids: List<Long>): Flow<Boolean> = flow {
    if (condition) {
        getDataFromApi(ids).onCompletion {
            // Do something
            emit(true)
        }.collect { data ->
            emit(true)
        }
    } else {
       	emit(false)
    }
}

fun getDataFromApi(ids: List<Long>): Flow<Data> = flow {
    emitAll(...)
}