https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dougie

09/04/2020, 3:32 AM
hey guys, there is a flow return a list that every item with a retrofit api service, then i want to get all detail from remote api in one time, not like
flatMapConcat
one by one.
flatMapMerge
can not do it, and start coroutines will break the flow are there any good solutions? thanks
👀 1
d

Daniele Segato

09/04/2020, 8:48 AM
I'm just a beginner with Coroutines / Flow so don't take for granted what i say. what if you use map and map them to DEFERRED tasks? (
async { }
) then you can await them in the order they come. You basically want what in Rx is called
flatMapConcatEager
right? what I suggest doesn't limit the number of concurrent calls to retrofit. I think i would try with something like this:
Copy code
myFlow
  .map { input ->
    // not sure if there's a way to specify how many concurrent
    async { performRetrofitCall(input) }
  }
  .map { it.await() }
I didn't try it tho', it is just what i would try to do
3 Views