PublishSubject with backpressure in RxJava 2.x
Asked Answered
A

2

17

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 ?

Acetometer answered 12/2, 2017 at 9:8 Comment(0)
D
30

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();
Doodle answered 12/2, 2017 at 11:16 Comment(2)
@Doodle How to call the onNext() of subscriber of Flowable in this case? I tried to do pp.onNext(1) but it's not calling the flowable's subscribers onNext()Umpteen
@SandipSoni Please open a question where you detail exactly what you have and what you tried, with source code.Doodle
D
5

I used at some point something like this:

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

emitterSubject.toFlowable(BackpressureStrategy.LATEST)
Disenfranchise answered 23/4, 2019 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.