-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
RxJava version 2.0.4
While migrating to RxJava 2, I ran into some behavioural differences between 1.x fromAsync()
and Observable.create()
. In particular, the emitter passed into fromAsync
handles onError()
emissions after unsubscription differently from the 2.x one.
In 2.x, if onError()
is invoked after the observable is disposed (e.g. emitter.isDisposed()
returns true), the error is routed to the default onError()
handler, resulting in an unhandled exception. This means that when emitting an error event, this should be guarded with a check to emitter.isDisposed()
. onNext()
and onCompleted
events after disposal are discarded like before in 1.x
In 1.x this is not the case, and the emitter will just ignore the error emission if the observable has been unsubscribed.
Personally I prefer the 1.x behaviour because it's less error prone and doesn't require a guard using isDisposed()
. Also because of this, migrating existing 1.x code to 2.x can be problematic. It took me a while to figure out why an error was thrown even though all of my subscriptions have explicit error handling.