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
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.
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.
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.
Observable: emit a stream elements (endlessly) Flowable: emit a stream of elements (endlessly, with backpressure) Single: emits exactly one element.
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.
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