Subscriber – the Observer interface

In RxKotlin 1.x, the Subscriber operator essentially became an Observer type in RxKotlin 2.x. There is an Observer type in RxKotlin 1.x, but the Subscriber value is what you pass to the subscribe() method, and it implements Observer. In RxJava 2.x, a Subscriber operator only exists when talking about Flowables

As you can see in the previous examples in this chapter, an Observer type is an interface with four methods in it, namely onNext(item:T), onError(error:Throwable), onComplete(), and onSubscribe(d:Disposable). As stated earlier, when we connect Observable to Observer, it looks for these four methods in the Observer type and calls them. Here is a short description of the following four methods:

  • onNext: The Observable calls this method of Observer to pass each of the items one by one
  • onComplete: When the Observable wants to denote that it's done with passing items to the onNext method, it calls the onComplete method of Observer
  • onError: When Observable faces any error, it calls the onError method to deal with the error if defined in the Observer  type, otherwise it throws the exception
  • onSubscribe: This method is called whenever a new Observable subscribes to Observer
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.237.24