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 ?
Flowable from FlowableOnSubscribe. RxJava 2 introduced a functional interface FlowableOnSubscribe, which represents a Flowable that starts emitting events after the consumer subscribes to it. Due to that, all clients will receive the same set of events, which makes FlowableOnSubscribe backpressure-safe.
Flowable. Flowable is typically used when an Observable is emitting huge amounts of data but the Observer is not able to handle this data emission. This is known as Back Pressure .
Flowable — same as Observable, but with backpressure support. Single — stream which can have only single event (either value or error) Maybe — same as Single, with distinction that it might complete without providing any value. Completable — stream which can only complete without emitting values.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With