Sample

See also

  • Official ReactiveX documentation: Sample
Observable.sample(interval=None, sampler=None, scheduler=None)

Samples the observable sequence at each interval.

Examples:

# Sampler tick sequence
res = source.sample(sample_observable)
# 5 seconds (5000 milliseconds)
res = source.sample(5000)
# 5 seconds
res = source.sample(5000, rx.scheduler.timeout)
Parameters:

source (Observable) – Source sequence to sample.

Keyword Arguments:
 
  • interval (int) – Interval at which to sample (specified as an integer denoting milliseconds).
  • scheduler (Secheduler) – Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
Returns:

sampled observable sequence.

Return type:

(Observable)

../../_images/sample.png
Observable.throttle_first(window_duration, scheduler=None)

Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.

Keyword arguments: window_duration – {timedelta} time to wait before emitting another item

after emitting the last item.
scheduler – {Scheduler} [Optional] the Scheduler to use internally to
manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.

Returns {Observable} An Observable that performs the throttle operation.

../../_images/throttleFirst.png
Observable.throttle_last(interval=None, sampler=None, scheduler=None)

Samples the observable sequence at each interval.

Examples:

# Sampler tick sequence
res = source.sample(sample_observable)
# 5 seconds (5000 milliseconds)
res = source.sample(5000)
# 5 seconds
res = source.sample(5000, rx.scheduler.timeout)
Parameters:

source (Observable) – Source sequence to sample.

Keyword Arguments:
 
  • interval (int) – Interval at which to sample (specified as an integer denoting milliseconds).
  • scheduler (Secheduler) – Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
Returns:

sampled observable sequence.

Return type:

(Observable)

../../_images/throttleLast.png