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

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.
主站蜘蛛池模板: 新源县| 普宁市| 读书| 宝兴县| 肇源县| 革吉县| 丹东市| 克东县| 安庆市| 荔波县| 石柱| 邓州市| 广安市| 钟山县| 鹤峰县| 淅川县| 西安市| 长沙县| 桦川县| 介休市| 城固县| 通州区| 峨眉山市| 额敏县| 全南县| 平原县| 峨眉山市| 内乡县| 常州市| 玉山县| 原阳县| 来凤县| 崇义县| 八宿县| 赤壁市| 瑞丽市| 平利县| 宁乡县| 芜湖市| 武夷山市| 枞阳县|