I have a question about running concurrent tasks. ...
# coroutines
s
I have a question about running concurrent tasks. I would like to have a flow that first computes the results from multiple different tasks that each return a flow of the same type, combine all the flows and emit the final result as a single flow. What i have now is:
Copy code
// Run multiple async tasks and combine them and enit as one flow
val finalFlow: Flow<SomeType> = flow{
    supervisorScope {
        val firstAsyncAction = async { firstAsyncActionFlow }
        val secondAsyncAction = async { secondAsyncActionFlow }
        val thirdAsyncAction = async { thirdAsyncActionFlow }

        emitAll(
            awaitAll(
                firstAsyncAction,
                secondAsyncAction,
                thirdAsyncAction
            ).merge()    
        )
    }
}

finalFlow.collect {
    // This runs multiple times discarding the previously sent items from the flow
}
However, this emits as soon as any of the async tasks complete which is not the desired result. How would i handle such a use case?