Monitoring the event stream
Although so far we have been using the Observable
operators to manipulate stream events, there are operators that allow us to monitor the events without changing them. These operators, known sometimes as utility operators, are able to react to the events or errors emitted on the Observable
chain created between the source Observable
and the final Subscriber
without creating any side effects.
Let's enumerate them and explain the more common utility operators used to observe the event stream:
doOnSubscribe(Action0)
: Registers anAction0
function to get called when aSubscriber
subscribes to theObservable
.doOnUnsubscribe(Action0)
: Registers anAction0
function to get called when aSubscriber
unsubscribes from theObservable
.doOnNext(Action1)
: Registers anAction1
to be called when a new event is emitted from the sourceObservable
. The Event<T>
object is also passed as an argument to theAction1
function.doOnCompleted(Action0)
: Registers anAction0
function...