Why threads are not observed

Why are threads not observable; The observed interface is largely a subset of Flowable; their implementation is almost the same.

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

+4
source share
2 answers

A slight regret about the introduction of backpressure in RxJava 0.x is that instead of having a separate base reactive class, the observable itself has been modernized. The main problem with backpressure is that many hot springs, such as user interface events, cannot be strong enough and cause an unexpected MissingBackpressureException (that is, newbies do not expect them).

We are trying to fix this situation in 2.x, with io.reactivex.Observable non-backpressured and the new io.reactivex.Flowable - the base reactive class with backpressure protection.

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

+5
source

Why Flowables not Observables

Conceptual separation. I would go with Flowable just because it can do all the other types. The community, however, strongly reflected the basic behavioral property of the individual types: Single , Maybe , Completable ...

The monitored interface is largely a subset of Flowable.

This is a common point of view from people who are probably not programmed daily. Unfortunately, for them, the system and type language (Java) do not allow such high-level abstractions to easily or simply specialize.

In addition, the implementation of backpressure requires specific algorithms and building blocks and can become quite complex. I recommend that you check the difference between one of the more complex operators: Flowable.flatMapIterable vs Observable.flatMapIterable .

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

Flowable implements Reactive-Streams interfaces, and therefore we cannot just declare Subscriber extends Observer and Subscription extends Disposable .

Also, sometime at the beginning of v2, Observable implemented by Publisher and caused a lot of ambiguity, and manual casting would be a major problem for library users.

+5
source

Source: https://habr.com/ru/post/1270230/


All Articles