UNPKG

3.6 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, ObservableInput } from '../types';
2export interface RepeatConfig {
3 /**
4 * The number of times to repeat the source. Defaults to `Infinity`.
5 */
6 count?: number;
7 /**
8 * If a `number`, will delay the repeat of the source by that number of milliseconds.
9 * If a function, it will provide the number of times the source has been subscribed to,
10 * and the return value should be a valid observable input that will notify when the source
11 * should be repeated. If the notifier observable is empty, the result will complete.
12 */
13 delay?: number | ((count: number) => ObservableInput<any>);
14}
15/**
16 * Returns an Observable that will resubscribe to the source stream when the source stream completes.
17 *
18 * <span class="informal">Repeats all values emitted on the source. It's like {@link retry}, but for non error cases.</span>
19 *
20 * ![](repeat.png)
21 *
22 * Repeat will output values from a source until the source completes, then it will resubscribe to the
23 * source a specified number of times, with a specified delay. Repeat can be particularly useful in
24 * combination with closing operators like {@link take}, {@link takeUntil}, {@link first}, or {@link takeWhile},
25 * as it can be used to restart a source again from scratch.
26 *
27 * Repeat is very similar to {@link retry}, where {@link retry} will resubscribe to the source in the error case, but
28 * `repeat` will resubscribe if the source completes.
29 *
30 * Note that `repeat` will _not_ catch errors. Use {@link retry} for that.
31 *
32 * - `repeat(0)` returns an empty observable
33 * - `repeat()` will repeat forever
34 * - `repeat({ delay: 200 })` will repeat forever, with a delay of 200ms between repetitions.
35 * - `repeat({ count: 2, delay: 400 })` will repeat twice, with a delay of 400ms between repetitions.
36 * - `repeat({ delay: (count) => timer(count * 1000) })` will repeat forever, but will have a delay that grows by one second for each repetition.
37 *
38 * ## Example
39 *
40 * Repeat a message stream
41 *
42 * ```ts
43 * import { of, repeat } from 'rxjs';
44 *
45 * const source = of('Repeat message');
46 * const result = source.pipe(repeat(3));
47 *
48 * result.subscribe(x => console.log(x));
49 *
50 * // Results
51 * // 'Repeat message'
52 * // 'Repeat message'
53 * // 'Repeat message'
54 * ```
55 *
56 * Repeat 3 values, 2 times
57 *
58 * ```ts
59 * import { interval, take, repeat } from 'rxjs';
60 *
61 * const source = interval(1000);
62 * const result = source.pipe(take(3), repeat(2));
63 *
64 * result.subscribe(x => console.log(x));
65 *
66 * // Results every second
67 * // 0
68 * // 1
69 * // 2
70 * // 0
71 * // 1
72 * // 2
73 * ```
74 *
75 * Defining two complex repeats with delays on the same source.
76 * Note that the second repeat cannot be called until the first
77 * repeat as exhausted it's count.
78 *
79 * ```ts
80 * import { defer, of, repeat } from 'rxjs';
81 *
82 * const source = defer(() => {
83 * return of(`Hello, it is ${new Date()}`)
84 * });
85 *
86 * source.pipe(
87 * // Repeat 3 times with a delay of 1 second between repetitions
88 * repeat({
89 * count: 3,
90 * delay: 1000,
91 * }),
92 *
93 * // *Then* repeat forever, but with an exponential step-back
94 * // maxing out at 1 minute.
95 * repeat({
96 * delay: (count) => timer(Math.min(60000, 2 ^ count * 1000))
97 * })
98 * )
99 * ```
100 *
101 * @see {@link repeatWhen}
102 * @see {@link retry}
103 *
104 * @param count The number of times the source Observable items are repeated, a count of 0 will yield
105 * an empty Observable.
106 */
107export declare function repeat<T>(countOrConfig?: number | RepeatConfig): MonoTypeOperatorFunction<T>;
108//# sourceMappingURL=repeat.d.ts.map
\No newline at end of file