官术网_书友最值得收藏!

Subscribers - the Observer interface

The Subscriber from RxKotlin 1.x,  essentially became an Observer in RxKotlin 2.x. There is an Observer interface in RxKotlin 1.x, but Subscriber is what you pass to the subscribe() method, and it implements Observer. However, In RxJava 2.x, Subscriber only exists when talking about Flowables, which we will cover in Chapter 4Introduction to Backpressure and Flowables.

As you can see in the previous examples in this chapter, Observer is an interface with four methods in it—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 Observer and calls them. So, the following is a short description of the four methods:

  • onNextObservable calls this method of Observer to pass each of the items one by one.
  • onComplete: When Observable wants to denote, it's done with passing items to the onNext method, and 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, otherwise, it throws the exception.
  • onSubscribe: This method is called whenever a new Observable subscribes to the Observer.
主站蜘蛛池模板: 香港| 永年县| 泰州市| 湛江市| 肇源县| 五寨县| 孟津县| 前郭尔| 九寨沟县| 章丘市| 高雄县| 余姚市| 河南省| 若尔盖县| 伊宁市| 海晏县| 泗阳县| 塔河县| 凤庆县| 乌兰浩特市| 三门峡市| 阿克苏市| 舞阳县| 曲水县| 沭阳县| 崇义县| 浦东新区| 乃东县| 鱼台县| 祁门县| 惠来县| 静海县| 潍坊市| 盱眙县| 都安| 阿拉尔市| 淅川县| 五寨县| 宜良县| 新蔡县| 神池县|