throttleTime.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Observable, SchedulerLike } from 'rxjs';
  2. import { ThrottleConfig } from 'rxjs/internal-compatibility';
  3. /**
  4. * Emits a value from the source Observable, then ignores subsequent source
  5. * values for `duration` milliseconds, then repeats this process.
  6. *
  7. * <span class="informal">Lets a value pass, then ignores source values for the
  8. * next `duration` milliseconds.</span>
  9. *
  10. * <img src="./img/throttleTime.png" width="100%">
  11. *
  12. * `throttleTime` 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. After `duration` milliseconds (or the time unit determined
  17. * internally by the optional `scheduler`) has passed, the timer is disabled,
  18. * and this process repeats for the next source value. Optionally takes a
  19. * {@link IScheduler} for managing timers.
  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.throttleTime(1000);
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link auditTime}
  27. * @see {@link debounceTime}
  28. * @see {@link delay}
  29. * @see {@link sampleTime}
  30. * @see {@link throttle}
  31. *
  32. * @param {number} duration Time to wait before emitting another value after
  33. * emitting the last value, measured in milliseconds or the time unit determined
  34. * internally by the optional `scheduler`.
  35. * @param {Scheduler} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
  36. * managing the timers that handle the throttling.
  37. * @return {Observable<T>} An Observable that performs the throttle operation to
  38. * limit the rate of emissions from the source.
  39. * @method throttleTime
  40. * @owner Observable
  41. */
  42. export declare function throttleTime<T>(this: Observable<T>, duration: number, scheduler?: SchedulerLike, config?: ThrottleConfig): Observable<T>;