java RxJava 2.0 - 如何将 Observable 转换为发布者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40877490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:31:29  来源:igfitidea点击:

RxJava 2.0 - How to convert Observable to Publisher

javareactive-programmingreactivexreactive-streamsrx-java2

提问by caioquirino

How to convert Observable to Publisher in RxJava version 2?

如何在 RxJava 版本 2 中将 Observable 转换为 Publisher?

In the first version we have the https://github.com/ReactiveX/RxJavaReactiveStreamsproject that do exactly what I need. But How can I do it in RxJava 2?

在第一个版本中,我们有https://github.com/ReactiveX/RxJavaReactiveStreams项目,它完全符合我的需要。但是我如何在 RxJava 2 中做到这一点?

回答by Yaroslav Stavnichiy

Use the following code:

使用以下代码:

Publisher publisher = observable.toFlowable(BackpressureStrategy.XXX);

As Observabledoes not implement backpressure, you need to select backpressure strategy when converting. See available choices here.

由于Observable没有实现背压,转换时需要选择背压策略。在此处查看可用选项。

Or use Flowableinstead of Observablein the first place. See herefor details.

或者首先使用Flowable而不是Observable。有关详细信息,请参见此处