iex
04/09/2019, 3:18 PMgsala
04/09/2019, 3:27 PMiex
04/09/2019, 3:30 PMiex
04/09/2019, 3:31 PMgsala
04/09/2019, 3:32 PMRok Koncina
04/10/2019, 1:59 PM.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.iex
04/12/2019, 7:43 AMReplaySubject
or UnicastSubject
(by one of the main RxJava contributors) instead.iex
04/12/2019, 7:45 AMiex
04/12/2019, 7:46 AMsubscribeOn 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