throttleTime.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var async_1 = require('../scheduler/async');
  3. var throttle_1 = require('../operators/throttle');
  4. var throttleTime_1 = require('../operators/throttleTime');
  5. /**
  6. * Emits a value from the source Observable, then ignores subsequent source
  7. * values for `duration` milliseconds, then repeats this process.
  8. *
  9. * <span class="informal">Lets a value pass, then ignores source values for the
  10. * next `duration` milliseconds.</span>
  11. *
  12. * <img src="./img/throttleTime.png" width="100%">
  13. *
  14. * `throttleTime` emits the source Observable values on the output Observable
  15. * when its internal timer is disabled, and ignores source values when the timer
  16. * is enabled. Initially, the timer is disabled. As soon as the first source
  17. * value arrives, it is forwarded to the output Observable, and then the timer
  18. * is enabled. After `duration` milliseconds (or the time unit determined
  19. * internally by the optional `scheduler`) has passed, the timer is disabled,
  20. * and this process repeats for the next source value. Optionally takes a
  21. * {@link IScheduler} for managing timers.
  22. *
  23. * @example <caption>Emit clicks at a rate of at most one click per second</caption>
  24. * var clicks = Rx.Observable.fromEvent(document, 'click');
  25. * var result = clicks.throttleTime(1000);
  26. * result.subscribe(x => console.log(x));
  27. *
  28. * @see {@link auditTime}
  29. * @see {@link debounceTime}
  30. * @see {@link delay}
  31. * @see {@link sampleTime}
  32. * @see {@link throttle}
  33. *
  34. * @param {number} duration Time to wait before emitting another value after
  35. * emitting the last value, measured in milliseconds or the time unit determined
  36. * internally by the optional `scheduler`.
  37. * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
  38. * managing the timers that handle the throttling.
  39. * @return {Observable<T>} An Observable that performs the throttle operation to
  40. * limit the rate of emissions from the source.
  41. * @method throttleTime
  42. * @owner Observable
  43. */
  44. function throttleTime(duration, scheduler, config) {
  45. if (scheduler === void 0) { scheduler = async_1.async; }
  46. if (config === void 0) { config = throttle_1.defaultThrottleConfig; }
  47. return throttleTime_1.throttleTime(duration, scheduler, config)(this);
  48. }
  49. exports.throttleTime = throttleTime;
  50. //# sourceMappingURL=throttleTime.js.map