本文整理汇总了Python中rx.core.Observable.timer方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.timer方法的具体用法?Python Observable.timer怎么用?Python Observable.timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.timer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delay_subscription
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import timer [as 别名]
def delay_subscription(self, duetime, scheduler=None):
"""Time shifts the observable sequence by delaying the subscription.
1 - res = source.delay_subscription(5000) # 5s
2 - res = source.delay_subscription(5000, Scheduler.timeout) # 5 seconds
duetime -- Absolute or relative time to perform the subscription at.
scheduler [Optional] Scheduler to run the subscription delay timer on.
If not specified, the timeout scheduler is used.
Returns time-shifted sequence.
"""
scheduler = scheduler or timeout_scheduler
def selector(_):
return Observable.empty()
return self.delay_with_selector(Observable.timer(duetime, scheduler), selector)
示例2: interval
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import timer [as 别名]
def interval(cls, period, scheduler=None):
"""Returns an observable sequence that produces a value after each
period.
Example:
1 - res = rx.Observable.interval(1000)
2 - res = rx.Observable.interval(1000, rx.Scheduler.timeout)
Keyword arguments:
period -- Period for producing the values in the resulting sequence
(specified as an integer denoting milliseconds).
scheduler -- [Optional] Scheduler to run the timer on. If not specified,
rx.Scheduler.timeout is used.
Returns an observable sequence that produces a value after each period.
"""
scheduler = scheduler or TimeoutScheduler()
return Observable.timer(period, period, scheduler)