Closed
Description
Currently, onError
cuts ahead of onNext
calls when you schedule work, but does not (cannot) when you use a single thread.
Observable.create(o -> {
o.onNext(1);
o.onError(new NotImplementedException());
})
.observeOn(Schedulers.newThread())
.subscribe(i -> System.out.println(i),
e -> System.out.println("error:" + e));
This yields error
instead of 1, error
as expected. Other implementations of Rx like Rx.Net do serialize notifications. This 'cut ahead' behavior is actually described as a common pitfall in RxJava by some.
Activity
akarnokd commentedon Nov 27, 2015
RxJava 2.0 will allow you to customize this behavior in many operators, including
observeOn
,delay
,combineLatest
,zip
,groupBy
,onBackpressureBuffer
,skipLast
andtakeLast
.I was planning to post a PR targeting
observeOn
to remove some unnecessary code (#3002) and may well do this as well.Dorus commentedon Dec 3, 2015
This is really scary nondeterministic behavior, and against Rx contract. I hope the (future) default will be to not lose data. If anything it might be an appropriate setting on the subscriber.
akarnokd commentedon Mar 14, 2016
The
observeOn
operator received an overload that takes adelayError
parameter you can set.Closing via #3682.