UNPKG

2.01 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 * Execute callback function when the observable completes
9 *
10 * ```ts
11 * import { interval } from 'rxjs';
12 * import { take, finalize } from 'rxjs/operators';
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, timer, noop } from 'rxjs';
35 * import { finalize, tap } from 'rxjs/operators';
36 *
37 * const source = interval(100).pipe(
38 * finalize(() => console.log('[finalize] Called')),
39 * tap({
40 * next: () => console.log('[next] Called'),
41 * error: () => console.log('[error] Not called'),
42 * complete: () => console.log('[tap complete] Not called')
43 * })
44 * );
45 *
46 * const sub = source.subscribe({
47 * next: x => console.log(x),
48 * error: noop,
49 * complete: () => console.log('[complete] Not called')
50 * });
51 *
52 * timer(150).subscribe(() => sub.unsubscribe());
53 *
54 * // results:
55 * // '[next] Called'
56 * // 0
57 * // '[finalize] Called'
58 * ```
59 *
60 * @param {function} callback Function to be called when source terminates.
61 * @return A function that returns an Observable that mirrors the source, but
62 * will call the specified function on termination.
63 */
64export declare function finalize<T>(callback: () => void): MonoTypeOperatorFunction<T>;
65//# sourceMappingURL=finalize.d.ts.map
\No newline at end of file