a zip code crypto-currency system good for red ONLY

throttle.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { throttle as higherOrder, defaultThrottleConfig } from '../operators/throttle';
  2. /**
  3. * Emits a value from the source Observable, then ignores subsequent source
  4. * values for a duration determined by another Observable, then repeats this
  5. * process.
  6. *
  7. * <span class="informal">It's like {@link throttleTime}, but the silencing
  8. * duration is determined by a second Observable.</span>
  9. *
  10. * <img src="./img/throttle.png" width="100%">
  11. *
  12. * `throttle` emits the source Observable values on the output Observable
  13. * when its internal timer is disabled, and ignores source values when the timer
  14. * is enabled. Initially, the timer is disabled. As soon as the first source
  15. * value arrives, it is forwarded to the output Observable, and then the timer
  16. * is enabled by calling the `durationSelector` function with the source value,
  17. * which returns the "duration" Observable. When the duration Observable emits a
  18. * value or completes, the timer is disabled, and this process repeats for the
  19. * next source value.
  20. *
  21. * @example <caption>Emit clicks at a rate of at most one click per second</caption>
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var result = clicks.throttle(ev => Rx.Observable.interval(1000));
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link audit}
  27. * @see {@link debounce}
  28. * @see {@link delayWhen}
  29. * @see {@link sample}
  30. * @see {@link throttleTime}
  31. *
  32. * @param {function(value: T): SubscribableOrPromise} durationSelector A function
  33. * that receives a value from the source Observable, for computing the silencing
  34. * duration for each source value, returned as an Observable or a Promise.
  35. * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults
  36. * to `{ leading: true, trailing: false }`.
  37. * @return {Observable<T>} An Observable that performs the throttle operation to
  38. * limit the rate of emissions from the source.
  39. * @method throttle
  40. * @owner Observable
  41. */
  42. export function throttle(durationSelector, config = defaultThrottleConfig) {
  43. return higherOrder(durationSelector, config)(this);
  44. }
  45. //# sourceMappingURL=throttle.js.map