PublishSubject with backpressure in RxJava 2.x

删除回忆录丶 提交于 2019-12-22 03:51:18

问题


I am currently choosing between RxJava 1.x or 2.x for my current project.

I basically need a PublishSubject with a backpressure strategy onBackpressureLatest().

I want to choose RxJava 2.x, but i can't quite get my head around on how to apply a backpressure strategy to a PublishSubject, as it inherits from Observable and not from Flowable.


Could you please tell me how to create a PublishSubject with a onBackpressureLatest() backpressure strategy in RxJava 2.x ?


回答1:


In 2.x the backpressure was moved to the base type Flowable and its hot partners PublishProcessor, ReplayProcessor etc.

PublishProcessor<Integer> pp = PublishProcessor.create();
Flowable<Integer> out = pp.onBackpressureLatest();



回答2:


I used at some point something like this:

Subject<Object> emitterSubject = PublishSubject.<Object>create().toSerialized();

emitterSubject.toFlowable(BackpressureStrategy.LATEST)


来源:https://stackoverflow.com/questions/42185853/publishsubject-with-backpressure-in-rxjava-2-x

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