Interval

See also

  • Official ReactiveX documentation: Interval
classmethod Observable.interval(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.

../../_images/interval.png
>>> import time
>>> source = rx.Observable.interval(50).take(5)
>>> def millis_since(t0):
...     return int((time.time() - t0)*1000)
>>> start = time.time()
>>> subscription = source.subscribe(
...     lambda value: print("Next: {} \t({} ms)".\
...                     format(value, millis_since(start))),
...     lambda error: print("Error: {} \t({} ms)".\
...                     format(error, millis_since(start))),
...     lambda: print("Complete! \t({} ms)".\
...                     format(millis_since(start))))
Next: 0       (54 ms)
Next: 1       (104 ms)
Next: 2       (155 ms)
Next: 3       (206 ms)
Next: 4       (263 ms)
Complete!     (263 ms)