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

Jan Skrasek

10/22/2019, 12:25 PM
Let's have a channel (ConflatedBroadcastChannel) wired in a model. What is an alternative to
SingleLiveData<T>
, e.g. something what observe value just once, but on multiple places (observers).
t

Tristan Caron

10/22/2019, 12:30 PM
.take(1)
would help you?
j

Jan Skrasek

10/22/2019, 12:37 PM
I think not, tak will return just first event and also cancel parent flow -> may cancel channel
t

Tristan Caron

10/22/2019, 12:56 PM
But a ConflatedBroadcastChannel takes 1 arguments, the initial value. It’s always keep the last value pushed into it. You could use
.value
and get an immediate result.
m

Matej Drobnič

10/23/2019, 5:09 AM
You need
flow.share
which is not here yet: https://github.com/Kotlin/kotlinx.coroutines/issues/1261
j

Jan Skrasek

10/23/2019, 10:01 AM
I don't see how share would help, I want the opossite - observe once.
5 Views