上QQ阅读APP看书,第一时间看更新
The just operator
The just operator returns an observable that emits only one item, and then it completes immediately. The marble diagram of this operator is shown in the following figure:
Figure 4.2: The just operator
Its prototype is as follows:
Observable.just(value, scheduler=None)
The following is an example of how to use it:
number = Observable.just(1)
number.subscribe(
on_next=lambda i: print("item: {}".format(i)),
on_error=lambda e: print("error: {}".format(e)),
on_completed=lambda: print("completed")
)
Upon subscription, the number 1, provided in the just operator, is emitted as the only item of the observable before the observable completes: