Observables
As we discussed earlier, in reactive programming, Observable
has an underlying computation that produces values that can be consumed by a consumer (Observer
). The most important thing here is that the consumer (Observer
) doesn't pull values here; rather, Observable
pushes the value to the consumer. So, we may say, an Observable
is a push-based, composable iterator that emits its items through a series of operators to the final Observer
, which finally consumes the items. Let's now break things sequentially to understand it better:
Observer
subscribes toObservable
Observable
starts emitting items that it has in itObserver
reacts to whatever itemObservable
emits
So, let's delve into how an Observable
works through its events/methods, namely, onNext
, onComplete
, and onError
.
How Observable works
As we stated earlier, an Observable
has three most important events/methods; let's discuss them one by one:
onNext
:Observable
passes all items one by one to this method.onComplete
: When all...