- Reactive Programming in Kotlin
- Rivu Chakraborty
- 204字
- 2021-07-02 22:26:42
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 4, Introduction 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:
- onNext: Observable 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.
推薦閱讀
- 企業數字化創新引擎:企業級PaaS平臺HZERO
- 有趣的二進制:軟件安全與逆向分析
- 算法競賽入門經典:習題與解答
- 使用GitOps實現Kubernetes的持續部署:模式、流程及工具
- Modern Programming: Object Oriented Programming and Best Practices
- Python醫學數據分析入門
- Sybase數據庫在UNIX、Windows上的實施和管理
- 一個64位操作系統的設計與實現
- 基于OPAC日志的高校圖書館用戶信息需求與檢索行為研究
- Power BI商業數據分析完全自學教程
- 金融商業算法建模:基于Python和SAS
- Chef Essentials
- Augmented Reality using Appcelerator Titanium Starter
- 二進制分析實戰
- 數據挖掘競賽實戰:方法與案例