- Hands-On Reactive Programming with Python
- Romain Picard
- 110字
- 2021-06-24 18:25:21
The empty operator
The empty operator returns an observable that completes immediately without sending any item:
Figure 3.6: The empty operator
The prototype of the empty operator is the following one:
Observable.empty(scheduler=None)
The empty operator can be used in the following way:
empty = Observable.empty()
empty.subscribe(
on_next=lambda i: print("item: {}".format(i)),
on_error=lambda e: print("error: {}".format(e)),
on_completed=lambda: print("completed")
)
The empty operator is useful mainly for testing and for stubbing:
- During unit testing, it can be used to test components against empty observables as input.
- When implementing a function step by step, for example when following a test-driven development process, an initial implementation can be done with empty observables.
推薦閱讀
- Mastering ElasticSearch
- 構建高可用Linux服務器(第4版)
- Linux系統文件安全實戰全攻略
- PLC控制程序精編108例
- Red Hat Enterprise Linux 8系統管理實戰
- Arch Linux Environment Setup How-to
- Windows Server 2012 Hyper-V Cookbook
- 玩到極致 iPhone 4S完全攻略
- Linux就該這么學
- 計算機系統的自主設計
- iOS 10快速開發:18天零基礎開發一個商業應用
- VMware Horizon Mirage Essentials
- OpenStack Essentials(Second Edition)
- OpenHarmony開發與實踐:基于紅莓RK2206開發板
- Linux指令從初學到精通