1 import { MonoTypeOperatorFunction } from '../types';
3 * Make a {@link ConnectableObservable} behave like a ordinary observable and automates the way
4 * you can connect to it.
6 * Internally it counts the subscriptions to the observable and subscribes (only once) to the source if
7 * the number of subscriptions is larger than 0. If the number of subscriptions is smaller than 1, it
8 * unsubscribes from the source. This way you can make sure that everything before the *published*
9 * refCount has only a single subscription independently of the number of subscribers to the target
12 * Note that using the {@link share} operator is exactly the same as using the *publish* operator
13 * (making the observable hot) and the *refCount* operator in a sequence.
19 * In the following example there are two intervals turned into connectable observables
20 * by using the *publish* operator. The first one uses the *refCount* operator, the
21 * second one does not use it. You will notice that a connectable observable does nothing
22 * until you call its connect function.
25 * import { interval } from 'rxjs';
26 * import { tap, publish, refCount } from 'rxjs/operators';
28 * // Turn the interval observable into a ConnectableObservable (hot)
29 * const refCountInterval = interval(400).pipe(
30 * tap((num) => console.log(`refCount ${num}`)),
35 * const publishedInterval = interval(400).pipe(
36 * tap((num) => console.log(`publish ${num}`)),
40 * refCountInterval.subscribe();
41 * refCountInterval.subscribe();
42 * // 'refCount 0' -----> 'refCount 1' -----> etc
43 * // All subscriptions will receive the same value and the tap (and
44 * // every other operator) before the publish operator will be executed
45 * // only once per event independently of the number of subscriptions.
47 * publishedInterval.subscribe();
48 * // Nothing happens until you call .connect() on the observable.
51 * @see {@link ConnectableObservable}
53 * @see {@link publish}
55 export declare function refCount<T>(): MonoTypeOperatorFunction<T>;