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

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.
主站蜘蛛池模板: 阿图什市| 长垣县| 民和| 奉贤区| 顺昌县| 金堂县| 青冈县| 瓮安县| 芜湖县| 壤塘县| 包头市| 叙永县| 礼泉县| 慈溪市| 昭觉县| 抚宁县| 安溪县| 台州市| 武穴市| 绵阳市| 静安区| 远安县| 鹤峰县| 平湖市| 临清市| 上高县| 汉川市| 休宁县| 涿州市| 图片| 固原市| 泾阳县| 汝州市| 阿拉善右旗| 永定县| 隆回县| 河曲县| 财经| 黔西县| 肥东县| 咸阳市|