Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava Subjects Vs Processors

I have been using Subjects in Rxjava for quite awhile but today a new term came up:

PublishProccessor would you please explain me the difference of the Processors and Subjects?

I have gone through the Docs but they are mostly the same.

thank you in advance

like image 659
seyed Jafari Avatar asked Jun 25 '18 05:06

seyed Jafari


People also ask

What are subjects in RxJava?

A Subject is a sort of bridge or proxy that acts both as a Subscriber and as an Observable. Because it is a Subscriber, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.

What is difference between single and Observable in RxJava?

Single is an Observable which only emits one item or throws an error. Single emits only one value and applying some of the operator makes no sense. Like we don't want to take value and collect it to a list.

What is difference between Flowable and Observable?

Observables are used when we have relatively few items over the time and there is no risk of overflooding consumers. If there is a possibility that the consumer can be overflooded, then we use Flowable. One example could be getting a huge amount of data from a sensor. They typically push out data at a high rate.

What is the difference between Observable and single?

Observable: emit a stream elements (endlessly) Flowable: emit a stream of elements (endlessly, with backpressure) Single: emits exactly one element.


1 Answers

For the Future readers:

The main difference is their base class, therefore the way that these two react to onNext event is different.

PublishProcessor is subclassed from Flowables so you can use a BackPressure Strategy when you make use of them. PublishSubject's superclass is Observable so at very least there is no BackPressure Strategy.

like image 181
seyed Jafari Avatar answered Dec 14 '22 20:12

seyed Jafari