Why is only `flow2` being called in `flow1.map{ fl...
# flow
s
Why is only
flow2
being called in
flow1.map{ flow2(it) }.flattenConcat()
?
flow1
is a
MutableStateFlow<MutableSet<Int>>
of db entity IDs,
flow2
is a Flow of lists of entities, which is updated when any of the flow's entities' properties change. I am updating the properties and then calling
flow1.emit(set)
, but only
flow2.onEach
is being called, not
flow1.map{}
. Any suggestions?
j
You mention
flow2.onEach
, but it's not clear how this is being used by
flow1.map{ flow2(it) }.flattenConcat()
. Can you provide a more detailed/complete code sample?
s
onEach
is just for logging purposes.
j
If
flow2.onEach
is called, then
flow1.map
must have been called at least once. Are you saying that you don't see execution of
flow1.map
when you call
flow1.emit
after the first time? If so, is it possible that
flow2
is exerting backpressure? If so, this from the MutableStateFlow docs may be relevant:
Copy code
Updates to the value are always conflated. So a slow collector skips fast updates, but always collects the most recently emitted value.
This would cause `emit`s to be ignored, and
map
would not execute for those dropped values.
w
I think it would be helpful if you provided some small code sample that demonstrates the issue, ideally one that’d run on https://play.kotlinlang.org