Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PublishSubject with backpressure in RxJava 2.x

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 ?

like image 732
Luca Fülbier Avatar asked Feb 12 '17 09:02

Luca Fülbier


People also ask

How do you use flowable in RxJava?

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.

What is flowable in android?

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 .

What is flowable in Kotlin?

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.


1 Answers

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();
like image 184
akarnokd Avatar answered Sep 28 '22 07:09

akarnokd