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

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.
主站蜘蛛池模板: 二连浩特市| 巴林左旗| 米易县| 皋兰县| 凤城市| 吉水县| 绵阳市| 两当县| 渭南市| 清涧县| 吴旗县| 泾阳县| 英吉沙县| 祁连县| 报价| 迭部县| 利川市| 海宁市| 垫江县| 屏山县| 连云港市| 佛教| 资源县| 鄱阳县| 三江| 咸宁市| 台北市| 黑水县| 青田县| 沂南县| 萨迦县| 嵊泗县| 榕江县| 理塘县| 海城市| 方城县| 武胜县| 宣汉县| 儋州市| 手机| 闵行区|