The Observable
As introduced in Chapter 1, Thinking Reactively, the Observable
is a push-based, composable iterator. For a given Observable<T>
, it pushes items (called emissions) of type T
through a series of operators until it finally arrives at a final Observer, which consumes the items. We will cover several ways to create an Observable
, but first, let's dive into how an Observable
works through its onNext()
, onCompleted()
, and onError()
calls.
How Observables work
Before we do anything else, we need to study how an Observable
sequentially passes items down a chain to an Observer
. At the highest level, an Observable
works by passing three types of events:
onNext()
: This passes each item one at a time from the sourceObservable
all the way down to theObserver
.onComplete()
: This communicates a completion event all the way down to theObserver
, indicating that no moreonNext()
calls will occur.onError()
: This communicates an error up the chain to theObserver
, where theObserver
typically...