source: trip-planner-front/node_modules/rxjs/src/internal/operators/auditTime.ts@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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