0中的Observable和Flowable有什么区别

0中的Observable和Flowable有什么区别

本文介绍了RxJava 2.0中的Observable和Flowable有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Observable和Flowable接口似乎完全相同。为什么Flowable是在RxJava 2.0中引入的?我何时应该使用Flowable over Observable?

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?

推荐答案

如:

我们试图通过让
io来补救2.x中的这种情况.reactivex.Observable 非背压和新的
io.reactivex.Flowable 是启用背压的基础反应类。

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.

当一段时间内物品相对较少(< 1000)时使用 Observable /或者没有风险生产者过度消费消费者,从而导致OOM。

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
当你有一个ob servable如此快速地发出物品,消费者无法跟上流量,导致已发射但未消耗的物品存在。

BackpressureWhen 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.

这篇关于RxJava 2.0中的Observable和Flowable有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:29