Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are Flowables not Observables

Why are Flowables not Observables; Observable interface is pretty much a subset of Flowable, their implementations are pretty much the same.

Why don't they implement a common interface so we can directly cast Flowable as Observable?

like image 220
Victor Grazi Avatar asked Dec 19 '22 07:12

Victor Grazi


2 Answers

Why are Flowables not Observables

Conceptional separation. I would have gone with Flowable only because that can do all the other types. The community, however, were strongly into reflecting the major behavioral property in separate types: Single, Maybe, Completable...

Observable interface is pretty much a subset of Flowable

This is a common viewpoint from people who likely don't program on a daily basis. Unfortunately for them, the type system and language (Java) doesn't let such high-level abstractions get specialized easily or at all.

Plus, implementing backpressure requires specific algorithms and building blocks and can get quite complicated. I encourage you to check out the difference between one of the more difficult operators: Flowable.flatMapIterable vs Observable.flatMapIterable.

Why don't they implement a common interface so we can directly cast Flowable as Observable

Flowable implements the Reactive-Streams interfaces and thus we can't just declare Subscriber extends Observer and Subscription extends Disposable.

Furthermore, at one time in early v2, Observable implemented Publisher and caused massive amounts of ambiguity and manual casting would have been a major pain point for library users.

like image 68
akarnokd Avatar answered Dec 29 '22 00:12

akarnokd


A small regret about introducing backpressure in RxJava 0.x is that instead of having a separate base reactive class, the Observable itself was retrofitted. The main issue with backpressure is that many hot sources, such as UI events, can't be reasonably backpressured and cause unexpected MissingBackpressureException (i.e., beginners don't expect them).

We try to remedy this situation in 2.x by having io.reactivex.Observable non-backpressured and the new io.reactivex.Flowable be the backpressure-enabled base reactive class.

https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#observable-and-flowable

like image 27
Kiskae Avatar answered Dec 29 '22 00:12

Kiskae