问题
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