https://kotlinlang.org logo
#rx
Title
# rx
a

alexsullivan114

02/18/2020, 2:41 PM
You could probably use a combination
share
and
buffer
to get that behavior, but I'd honestly just go the behavior subject route.
i

iex

02/18/2020, 2:45 PM
Hmm but that makes things more verbose. Why would I prefer it (if it's possible using those operators)?
though the behavior subject can be called with startWith(observable) or something like that, right?
a

alexsullivan114

02/18/2020, 3:08 PM
It's an observable so you can use all of the normal operators
I think the
share
+
buffer
route (and I'm not sure that would actually work) will be more verbose and require more cognitive load to reason through
BehaviorSubject is very very simple and one line to declare, and one extra line to expose hidden.
share
+
replay
is probably what you actually want if you're going the observable route
z

Zach Klippenstein (he/him) [MOD]

02/18/2020, 4:49 PM
share
probably doesn't make sense with
replay
, they're both multicasting operators (
share
is just
publish().refCount()
). You want just
replay(1)
and then either
refCount
,
autoConnect
, or to just call
connect
yourself on the returned
ConnectableObservable
.
👍 2
i

iex

02/18/2020, 9:09 PM
awesome, thanks!
t

trevjones

02/19/2020, 7:20 PM