What is the difference between Observable and Flowable in RxJava 2.0?

﹥>﹥吖頭↗ 提交于 2020-01-09 16:49:11

问题


Observable and Flowable interfaces seem to be identical. Why Flowable was introduced in RxJava 2.0? When should I prefer to use Flowable over Observable?


回答1:


As stated in the documentation:

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.

Use Observable when you have relatively few items over time (<1000) and/or there's no risk of producer overflooding consumers and thus causing OOM.

Use Flowable when you have relatively large amount of items and you need to carefully control how Producer behaves in order to to avoid resource exhaustion and/or congestion.


Backpressure When you have an observable which emits items so fast that consumer can’t keep up with the flow leading to the existence of emitted but unconsumed items.

How unconsumed items, which are emitted by observables but not consumed by subscribers, are managed and controlled is what backpressure strategy deals with.

Ref link



来源:https://stackoverflow.com/questions/40947649/what-is-the-difference-between-observable-and-flowable-in-rxjava-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!