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

ubu

01/23/2020, 11:11 AM
Hi there. Inside some
ViewModel
, I tend to use
ConflatedBroadcastChannel
(
fooChannel
) as some kind of reactive field, which I transform to
Flow
(
fooFlow
), which I hold also as a field of this
ViewModel
when needed, in order to observe it, combine streams, etc. For me, it’s like using
BehaviorSubject
from
RxJava
. Sometimes I need to access the current value of this channel to perform some fire-and-forget operation . What is then more correct, less error-prone:
fooFlow.take(1).collect {  performSomeSuspendableOperation(it) }
or
performSomeSuspendableOperation(fooChannel.value)
Thanks guys!
z

Zach Klippenstein (he/him) [MOD]

01/23/2020, 3:39 PM
I think the latter is simpler, the intent is more obvious, and it's easier to read especially if you're new to programming with streams like this. Can't think of any reason to do the former if you've got direct access to the CBC.
👍 1
2 Views