This part of code will emit the result of the requ...
# flow
g
This part of code will emit the result of the request one by one. Can someone please tell me how to bunch the results of all the requests into a list?
Copy code
suspend fun getOffers(
    categories: List<Category>
): Flow<Offer> = categories
    .asFlow()
    .flatMapMerge(concurrency = 20) {
        suspend { api.requestOffers(it) }.asFlow()
    }
c
You should use buffer before
flatMapMerge
g
I tried but doesnt work
Copy code
suspend fun getOffers(
    categories: List<Category>
): Flow<Offer> = categories
    .asFlow()
    .buffer()
    .flatMapMerge(concurrency = 20) {
        suspend { api.requestOffers(it) }.asFlow()
    }
    .map {
       // here I still see one result, not a list of results
     }
m
Copy code
suspend fun getOffers(
    categories: List<Category>
): Flow<Offer> = coroutineScope { 
categories
    .map { 
       async {
         api.requestOffers(it)
       }
    }.awaitAll()
}.asFlow()
g
yes that works! Thank you @MR3Y