Untitled.kt
# rx
i
Untitled.kt
g
Are you pushing anything to the subject?
i
no
it's just subscribing to the observable
g
Ah, I missed you were subscribing with the subject.
r
It is strange that it affects it at all...
.doOnNext
,
.doOnError
and
.subscribe
all create new instances, so you're actually not changing the original mySubject at all. When you call
myObs.subscribe(mySubject)
you're calling it with the empty subject as you created it at the field level. But this does not answer your original question... I'd guess that you unsubscribe from the subs just after calling the method? If that's the case than without the IO scheduler this printing code is called immediately but when you execute it on the IO thread, it's execution is delayed for a super short period, just enough to be interrupted... My guess.
i
@Rok Koncina yes, it's a race condition. I was told to use
ReplaySubject
or
UnicastSubject
(by one of the main RxJava contributors) instead.
oh and no, I'm not unsubscribing
this was his explanation:
subscribeOn on a Subject has no practical effect. It moves the subscription to another thread and you drive the subject still from the main thread. There is a race and thus the subscribe { Log.d("mydebug", "event: $it") } may not happen in time to see the value from myObs