Timeout

See also

  • Official ReactiveX documentation: Timeout
Observable.timeout(duetime, other=None, scheduler=None)

Returns the source observable sequence or the other observable sequence if duetime elapses.

Example:

from datetime import datetime

# As a date
res = source.timeout(datetime.now())

# 5 seconds (5000 milliseconds)
res = source.timeout(5000); # 5 seconds

# As a date and timeout observable
res = source.timeout(datetime.now(),
                     rx.Observable.return_value(42))

# 5 seconds and timeout observable
res = source.timeout(5000, rx.Observable.return_value(42))

# As a date and timeout observable
res = source.timeout(datetime.now(),
                     rx.Observable.return_value(42),
                     rx.Scheduler.timeout)

# 5 seconds and timeout observable
res = source.timeout(5000,
                     rx.Observable.return_value(42),
                     rx.Scheduler.timeout)
Keyword Arguments:
 
  • duetime (int, datetime.datetime) – Absolute (specified as a datetime.datetime object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
  • other (Observable) – Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
  • scheduler (Scheduler) – Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
Returns:

The source sequence switching to the other sequence in case of a timeout.

Return type:

(Observable)

../../_images/timeout3.png ../../_images/timeout4.png ../../_images/timeout5.png ../../_images/timeout6.png
Observable.timeout_with_selector(first_timeout=None, timeout_duration_selector=None, other=None)

Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.

Examples:

res = source.timeout_with_selector(rx.Observable.timer(500))
res = source.timeout_with_selector(rx.Observable.timer(500),
        lambda x: rx.Observable.timer(200))
res = source.timeout_with_selector(rx.Observable.timer(500),
        lambda x: rx.Observable.timer(200)),
        rx.Observable.return_value(42))
Keyword Arguments:
 
  • first_timeout (Observable) – Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
  • timeout_duration_selector – Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
  • other – Sequence to return in case of a timeout. If not provided, this is set to Observable.throw_exception().
Returns:

Returns the source sequence switching to the other sequence in case of a timeout.

Return type:

(Observable)

../../_images/timeoutWithSelector3.png ../../_images/timeoutWithSelector4.png ../../_images/timeoutWithSelector5.png ../../_images/timeoutWithSelector6.png