sampleTime.d.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Observable, SchedulerLike } from 'rxjs';
  2. /**
  3. * Emits the most recently emitted value from the source Observable within
  4. * periodic time intervals.
  5. *
  6. * <span class="informal">Samples the source Observable at periodic time
  7. * intervals, emitting what it samples.</span>
  8. *
  9. * <img src="./img/sampleTime.png" width="100%">
  10. *
  11. * `sampleTime` periodically looks at the source Observable and emits whichever
  12. * value it has most recently emitted since the previous sampling, unless the
  13. * source has not emitted anything since the previous sampling. The sampling
  14. * happens periodically in time every `period` milliseconds (or the time unit
  15. * defined by the optional `scheduler` argument). The sampling starts as soon as
  16. * the output Observable is subscribed.
  17. *
  18. * @example <caption>Every second, emit the most recent click at most once</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var result = clicks.sampleTime(1000);
  21. * result.subscribe(x => console.log(x));
  22. *
  23. * @see {@link auditTime}
  24. * @see {@link debounceTime}
  25. * @see {@link delay}
  26. * @see {@link sample}
  27. * @see {@link throttleTime}
  28. *
  29. * @param {number} period The sampling period expressed in milliseconds or the
  30. * time unit determined internally by the optional `scheduler`.
  31. * @param {Scheduler} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
  32. * managing the timers that handle the sampling.
  33. * @return {Observable<T>} An Observable that emits the results of sampling the
  34. * values emitted by the source Observable at the specified time interval.
  35. * @method sampleTime
  36. * @owner Observable
  37. */
  38. export declare function sampleTime<T>(this: Observable<T>, period: number, scheduler?: SchedulerLike): Observable<T>;