sampleTime.d.ts 1.7 KB

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