hey everybody I have a `coroutine channel` in a `v...
# announcements
m
hey everybody I have a
coroutine channel
in a
viewmodel
, how can I collect changes in multiple places? I tried code below:
Copy code
#1
channel.consumeAsFlow {}

#2
channel.consumeAsFlow {}

#3
channel.consumeAsFlow {}
but only the first one will get triggered
d
Do you want each collector to see every item? Or only one collector should see one item?
m
yes I want each collector to see every item
y
Try
channel.receiveAsFlow().shareIn(Dispatchers.Default)
and make sure to use that same flow everywhere. You have to share the flow because otherwise each item is only seen by one subscriber according to the documentation
m
thank you i'll try
d
If possible I recommend replacing the whole channel with a shared flow.
2