- Hands-On Reactive Programming with Python
- Romain Picard
- 159字
- 2021-06-24 18:25:24
The interval operator
In cases in which some items must be emitted at a fixed interval, the interval operator can be used instead of the timer operator. Its behavior is the same as the timer operator, wherein the same value is provided in duetime, a period parameter. This is how it is implemented. Its marble diagram is shown in the following figure:
Figure 4.9: The interval operator
Its prototype is as follows:
Observable.interval(period, scheduler=None)
The period parameter is the value, in milliseconds, of the period of item emission. This operator can be used as follows:
import datetime
ticks = Observable.interval(1000)
ticks.subscribe(
on_next=lambda i: print("tick {} at {}".format(
i, datetime.datetime.now())),
on_error=lambda e: print("error: {}".format(e)),
on_completed=lambda: print("completed")
)
The preceding example provides the same results as the second example of the timer operator, as follows:
tick 0 at 2018-06-23 22:07:32.488799 tick 1 at 2018-06-23 22:07:33.491213 tick 2 at 2018-06-23 22:07:34.493068 tick 3 at 2018-06-23 22:07:35.495030 tick 4 at 2018-06-23 22:07:36.500543
...
推薦閱讀
- Kubernetes修煉手冊
- Linux設(shè)備驅(qū)動開發(fā)詳解(第2版)
- 每天5分鐘玩轉(zhuǎn)Kubernetes
- 發(fā)布!設(shè)計與部署穩(wěn)定的分布式系統(tǒng)(第2版)
- UNIX操作系統(tǒng)設(shè)計
- 網(wǎng)絡(luò)操作系統(tǒng):Windows Server 2003管理與應(yīng)用
- Implementing Azure DevOps Solutions
- Linux操作系統(tǒng)應(yīng)用編程
- 嵌入式系統(tǒng)原理及開發(fā)
- 細說Linux基礎(chǔ)知識
- Windows 7應(yīng)用入門與技巧
- 一學就會:Windows Vista應(yīng)用完全自學手冊
- iOS 8開發(fā)指南
- Windows Server 2008組網(wǎng)技術(shù)與實訓(第3版)
- VMware Horizon Mirage Essentials