UNPKG

1.92 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction } from '../types';
2/**
3 * Returns an Observable that mirrors the source Observable, but will call a specified function when
4 * the source terminates on complete or error.
5 * The specified function will also be called when the subscriber explicitly unsubscribes.
6 *
7 * ## Examples
8 *
9 * Execute callback function when the observable completes
10 *
11 * ```ts
12 * import { interval, take, finalize } from 'rxjs';
13 *
14 * // emit value in sequence every 1 second
15 * const source = interval(1000);
16 * const example = source.pipe(
17 * take(5), //take only the first 5 values
18 * finalize(() => console.log('Sequence complete')) // Execute when the observable completes
19 * );
20 * const subscribe = example.subscribe(val => console.log(val));
21 *
22 * // results:
23 * // 0
24 * // 1
25 * // 2
26 * // 3
27 * // 4
28 * // 'Sequence complete'
29 * ```
30 *
31 * Execute callback function when the subscriber explicitly unsubscribes
32 *
33 * ```ts
34 * import { interval, finalize, tap, noop, timer } from 'rxjs';
35 *
36 * const source = interval(100).pipe(
37 * finalize(() => console.log('[finalize] Called')),
38 * tap({
39 * next: () => console.log('[next] Called'),
40 * error: () => console.log('[error] Not called'),
41 * complete: () => console.log('[tap complete] Not called')
42 * })
43 * );
44 *
45 * const sub = source.subscribe({
46 * next: x => console.log(x),
47 * error: noop,
48 * complete: () => console.log('[complete] Not called')
49 * });
50 *
51 * timer(150).subscribe(() => sub.unsubscribe());
52 *
53 * // results:
54 * // '[next] Called'
55 * // 0
56 * // '[finalize] Called'
57 * ```
58 *
59 * @param {function} callback Function to be called when source terminates.
60 * @return A function that returns an Observable that mirrors the source, but
61 * will call the specified function on termination.
62 */
63export declare function finalize<T>(callback: () => void): MonoTypeOperatorFunction<T>;
64//# sourceMappingURL=finalize.d.ts.map
\No newline at end of file