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

Maciek

09/23/2019, 12:21 PM
Hey guys, question about wiring observables through subjects. My cold finite observable will not come down the downstream unless I'll make subscription with lambda and call manual
onNext
on
subject
. Can someone explain why `subscribe`method on observable where you pass whole
subject
object is not working the same way? Also what is happening with disposable from such
subscribe
? Is it the same disposable when you make subscription on the
subject
?
a

arekolek

09/23/2019, 12:37 PM
Probably because
observable.subscribe(subject)
will forward
onComplete
to the subject as well [1], and to quote David Karnok: “When a
BehaviorProcessor
is terminated, the cached value is no longer available to late
Subscribers
.” [2] [1] https://github.com/JakeWharton/RxRelay [2] https://stackoverflow.com/questions/47982511/test-that-rxjava-behaviorprocessor-emits-a-value
either call
observable.subscribe(subject::onNext)
(like you did in first example), or use a
Relay
and
observable.subscribe(relay)
will work as you expect (which is still like the first example, because it implements
Consumer
)
m

Maciek

09/23/2019, 1:27 PM
Thanks a ton for explanation! As you said
Relay
is working as expected, but it actually uses the same method as lambda
subscribe
. It's the one with the
Consumer
, when you're calling
subscribe
with normal
subject
it's using overload with
Observer
which is few methods down the line after
subscribe
with
Consumer
. Difference is still that
subscribe
from
subject
won't return
disposable
and from
relay
and
lambda
will.
5 Views