UNPKG

3.26 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
2/**
3 * Emits a value from the source Observable, then ignores subsequent source
4 * values for `duration` milliseconds, then repeats this process.
5 *
6 * <span class="informal">Lets a value pass, then ignores source values for the
7 * next `duration` milliseconds.</span>
8 *
9 * ![](throttleTime.png)
10 *
11 * `throttleTime` emits the source Observable values on the output Observable
12 * when its internal timer is disabled, and ignores source values when the timer
13 * is enabled. Initially, the timer is disabled. As soon as the first source
14 * value arrives, it is forwarded to the output Observable, and then the timer
15 * is enabled. After `duration` milliseconds (or the time unit determined
16 * internally by the optional `scheduler`) has passed, the timer is disabled,
17 * and this process repeats for the next source value. Optionally takes a
18 * {@link SchedulerLike} for managing timers.
19 *
20 * ## Examples
21 *
22 * #### Limit click rate
23 *
24 * Emit clicks at a rate of at most one click per second
25 * ```ts
26 * import { fromEvent } from 'rxjs';
27 * import { throttleTime } from 'rxjs/operators';
28 *
29 * const clicks = fromEvent(document, 'click');
30 * const result = clicks.pipe(throttleTime(1000));
31 * result.subscribe(x => console.log(x));
32 * ```
33 *
34 * #### Double Click
35 *
36 * The following example only emits clicks which happen within a subsequent
37 * delay of 400ms of the previous click. This for example can emulate a double
38 * click. It makes use of the `trailing` parameter of the throttle configuration.
39 *
40 * ```ts
41 * import { fromEvent, asyncScheduler } from 'rxjs';
42 * import { throttleTime, withLatestFrom } from 'rxjs/operators';
43 *
44 * // defaultThottleConfig = { leading: true, trailing: false }
45 * const throttleConfig = {
46 * leading: false,
47 * trailing: true
48 * }
49 *
50 * const click = fromEvent(document, 'click');
51 * const doubleClick = click.pipe(
52 * throttleTime(400, asyncScheduler, throttleConfig)
53 * );
54 *
55 * doubleClick.subscribe((throttleValue: Event) => {
56 * console.log(`Double-clicked! Timestamp: ${throttleValue.timeStamp}`);
57 * });
58 * ```
59 *
60 * If you enable the `leading` parameter in this example, the output would be the primary click and
61 * the double click, but restricts additional clicks within 400ms.
62 *
63 * @see {@link auditTime}
64 * @see {@link debounceTime}
65 * @see {@link delay}
66 * @see {@link sampleTime}
67 * @see {@link throttle}
68 *
69 * @param duration Time to wait before emitting another value after
70 * emitting the last value, measured in milliseconds or the time unit determined
71 * internally by the optional `scheduler`.
72 * @param scheduler The {@link SchedulerLike} to use for
73 * managing the timers that handle the throttling. Defaults to {@link asyncScheduler}.
74 * @param config a configuration object to define `leading` and
75 * `trailing` behavior. Defaults to `{ leading: true, trailing: false }`.
76 * @return A function that returns an Observable that performs the throttle
77 * operation to limit the rate of emissions from the source.
78 */
79export declare function throttleTime<T>(duration: number, scheduler?: SchedulerLike, config?: import("./throttle").ThrottleConfig): MonoTypeOperatorFunction<T>;
80//# sourceMappingURL=throttleTime.d.ts.map
\No newline at end of file