throttleTime.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { ThrottleConfig } from './throttle';
  2. import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
  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. * ![](throttleTime.png)
  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 SchedulerLike} for managing timers.
  20. *
  21. * ## Example
  22. * Emit clicks at a rate of at most one click per second
  23. * ```javascript
  24. * import { fromEvent } from 'rxjs';
  25. * import { throttleTime } from 'rxjs/operators';
  26. *
  27. * const clicks = fromEvent(document, 'click');
  28. * const result = clicks.pipe(throttleTime(1000));
  29. * result.subscribe(x => console.log(x));
  30. * ```
  31. *
  32. * @see {@link auditTime}
  33. * @see {@link debounceTime}
  34. * @see {@link delay}
  35. * @see {@link sampleTime}
  36. * @see {@link throttle}
  37. *
  38. * @param {number} duration Time to wait before emitting another value after
  39. * emitting the last value, measured in milliseconds or the time unit determined
  40. * internally by the optional `scheduler`.
  41. * @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
  42. * managing the timers that handle the throttling.
  43. * @param {Object} config a configuration object to define `leading` and
  44. * `trailing` behavior. Defaults to `{ leading: true, trailing: false }`.
  45. * @return {Observable<T>} An Observable that performs the throttle operation to
  46. * limit the rate of emissions from the source.
  47. * @method throttleTime
  48. * @owner Observable
  49. */
  50. export declare function throttleTime<T>(duration: number, scheduler?: SchedulerLike, config?: ThrottleConfig): MonoTypeOperatorFunction<T>;