I have 2 flows, one of them is cold, another is ho...
# flow
r
I have 2 flows, one of them is cold, another is hot. The goal is to
merge
them, and collect all values they produce(and complete them all when the resulting flow completes). Issue: no items emitted, when hot one is idle. What is the nice way to combine two flows, making the resulting one - cold? where: • banEvents: MutableStateFlow • chatMessagesOutput: Flow
image.png
c
r
I mean all values from both without any order
c
Then you can use the second link
r
I've tried that out at first place, but my Turbine tests fails after using that operator. Says "no values produced in 10s"(our timeout for flow testing)
c
You can add
.onEach { println("some message: $it") }
to both of your flows (before the merge) to check that they do emit values
onEach
prints whatever goes through the flow without impacting it
r
Yes, Ivan, that's the point, the StateFlow emits nothing in this particular case
k
From the screen shot, is
chatMessages
the
StateFlow
?
r
@Kevin Worth no, it is cold
Flow
k
banEvents
, then?
r
yes
banEvents with
filterNotNull
becomes
Flow
as well
Let's do this one: I'll write some tests using different cases and then return here with my results
k
And
filterNotNull().onEach { println(it) }
prints nothing? Are you sure there’s an
emit
somewhere on
banEvents
?
r
Seems like I'm missing something
@Kevin Worth that's the case! It is IDLE, so nothing emitted there.
Is it MUST that it emits?
k
I think it would help to see more of the code, to try to get to an answer.
r
OK, guys, seems like the resulting flow (after
merge
) just never completes, that's why I'm catching the error in Turbine test(yes, I still receive chat messages, no bans since they are null)