Hi everyone, I have a question, Is possible collec...
# coroutines
k
Hi everyone, I have a question, Is possible collect/process more than one flow inside launch block? my code is like
Copy code
launch{
flow1.collect{ ... }
flow2.collect{ ... }
...
}
but only flow1 is executed, if comment flow1 then flow2 is executed
n
Well everything after the collect will suspend, until your first flow terminates/closes this way
So you need to collect them in different scopes
k
wow, that make sense, my flow1 is an infinite loop
Copy code
while(true){
emit(data)
delay(1000)
}
j
n
Yupp. Most of the time I'm also using the
flow.onEach { .... }.launchIn(yourScope)
as @Jason Ostrander suggested
k
thank you! I will use it
g
So you need to collect them in different scopes
Not different scopes, but different coroutine to collect each, scope can be the same
n
Yes, you're right. My bad, I didn't mean the
coroutineScope
, rather the scope of the lambda/launch