throttleTime.js 2.3 KB

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