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

Pablo

06/08/2021, 1:23 PM
Does it make sense to have a
flow
that inside does an
async{}
call? For instance
Copy code
flow<List<Foo>>{
  val list = getFromApi()
  val one = async(<http://Dispatchers.IO|Dispatchers.IO>)
  val two = async(<http://Dispatchers.IO|Dispatchers.IO>)
  val correctList = one.await() + two.await()
  emit(correctList)
}
Or it's better to use async without flow here? That's pseudo because to do
async
I need a
coroutineScope
is there any way to get it from the
flow
?
e

Erik

06/08/2021, 1:38 PM
You need a scope to collect the flow. Or a
coroutineScope
to do the
async
calls. I would do the latter if it really doesn't need to be a flow.
p

Pablo

06/08/2021, 2:10 PM
means? you wouldn't use flow?
👌 1
u

uli

06/08/2021, 2:39 PM
async basically does the same thing as an rx single. just simpler. That’s probably why there is no SingleFlow’
z

Zach Klippenstein (he/him) [MOD]

06/08/2021, 6:16 PM
It would probably be more idiomatic to just make this a suspend function, so that it’s up to the caller whether to wait for it to finish or run concurrently.
👍 1
☝️ 1
2 Views