Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { Operator } from '../Operator';
|
---|
2 | import { Subscriber } from '../Subscriber';
|
---|
3 | import { Subscription } from '../Subscription';
|
---|
4 | import { Observable } from '../Observable';
|
---|
5 | import { MonoTypeOperatorFunction, TeardownLogic } from '../types';
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Returns an Observable that mirrors the source Observable, but will call a specified function when
|
---|
9 | * the source terminates on complete or error.
|
---|
10 | * @param {function} callback Function to be called when source terminates.
|
---|
11 | * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.
|
---|
12 | * @method finally
|
---|
13 | * @owner Observable
|
---|
14 | */
|
---|
15 | export function finalize<T>(callback: () => void): MonoTypeOperatorFunction<T> {
|
---|
16 | return (source: Observable<T>) => source.lift(new FinallyOperator(callback));
|
---|
17 | }
|
---|
18 |
|
---|
19 | class FinallyOperator<T> implements Operator<T, T> {
|
---|
20 | constructor(private callback: () => void) {
|
---|
21 | }
|
---|
22 |
|
---|
23 | call(subscriber: Subscriber<T>, source: any): TeardownLogic {
|
---|
24 | return source.subscribe(new FinallySubscriber(subscriber, this.callback));
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * We need this JSDoc comment for affecting ESDoc.
|
---|
30 | * @ignore
|
---|
31 | * @extends {Ignored}
|
---|
32 | */
|
---|
33 | class FinallySubscriber<T> extends Subscriber<T> {
|
---|
34 | constructor(destination: Subscriber<T>, callback: () => void) {
|
---|
35 | super(destination);
|
---|
36 | this.add(new Subscription(callback));
|
---|
37 | }
|
---|
38 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.