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

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.
主站蜘蛛池模板: 内黄县| 宁晋县| 东方市| 乡宁县| 淄博市| 临夏市| 商城县| 芦山县| 塘沽区| 黑山县| 台前县| 茂名市| 区。| 温州市| 平邑县| 巴楚县| 涿鹿县| 晋城| 额尔古纳市| 分宜县| 明溪县| 大丰市| 鄂伦春自治旗| 太和县| 洪雅县| 津市市| 台山市| 舞钢市| 仪征市| 吉木萨尔县| 宜兴市| 满城县| 海晏县| 天全县| 长泰县| 庆城县| 徐汇区| 绥阳县| 建德市| 同江市| 旬邑县|