Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auditTime.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { async } from '../scheduler/async';
  2. import { audit } from './audit';
  3. import { timer } from '../observable/timer';
  4. import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
  5. /**
  6. * Ignores source values for `duration` milliseconds, then emits the most recent
  7. * value from the source Observable, then repeats this process.
  8. *
  9. * <span class="informal">When it sees a source value, it ignores that plus
  10. * the next ones for `duration` milliseconds, and then it emits the most recent
  11. * value from the source.</span>
  12. *
  13. * ![](auditTime.png)
  14. *
  15. * `auditTime` is similar to `throttleTime`, but emits the last value from the
  16. * silenced time window, instead of the first value. `auditTime` emits the most
  17. * recent value from the source Observable on the output Observable as soon as
  18. * its internal timer becomes disabled, and ignores source values while the
  19. * timer is enabled. Initially, the timer is disabled. As soon as the first
  20. * source value arrives, the timer is enabled. After `duration` milliseconds (or
  21. * the time unit determined internally by the optional `scheduler`) has passed,
  22. * the timer is disabled, then the most recent source value is emitted on the
  23. * output Observable, and this process repeats for the next source value.
  24. * Optionally takes a {@link SchedulerLike} for managing timers.
  25. *
  26. * ## Example
  27. *
  28. * Emit clicks at a rate of at most one click per second
  29. * ```ts
  30. * import { fromEvent } from 'rxjs';
  31. * import { auditTime } from 'rxjs/operators';
  32. *
  33. * const clicks = fromEvent(document, 'click');
  34. * const result = clicks.pipe(auditTime(1000));
  35. * result.subscribe(x => console.log(x));
  36. * ```
  37. *
  38. * @see {@link audit}
  39. * @see {@link debounceTime}
  40. * @see {@link delay}
  41. * @see {@link sampleTime}
  42. * @see {@link throttleTime}
  43. *
  44. * @param {number} duration Time to wait before emitting the most recent source
  45. * value, measured in milliseconds or the time unit determined internally
  46. * by the optional `scheduler`.
  47. * @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
  48. * managing the timers that handle the rate-limiting behavior.
  49. * @return {Observable<T>} An Observable that performs rate-limiting of
  50. * emissions from the source Observable.
  51. * @method auditTime
  52. * @owner Observable
  53. */
  54. export function auditTime<T>(duration: number, scheduler: SchedulerLike = async): MonoTypeOperatorFunction<T> {
  55. return audit(() => timer(duration, scheduler));
  56. }