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
RxJava 2.0 - How to convert Observable to Publisher
提问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。有关详细信息,请参见此处。

