Code coverage report for src/operator/finally.ts

Statements: 100% (17 / 17)      Branches: 100% (0 / 0)      Functions: 100% (6 / 6)      Lines: 100% (14 / 14)      Ignored: none     

All files » src/operator/ » finally.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  1 1                 1 6     1 6     1 6   1   1 1 6 6   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Observable} from '../Observable';
 
/**
 * Returns an Observable that mirrors the source Observable, but will call a specified function when
 * the source terminates on complete or error.
 * @param {function} finallySelector function to be called when source terminates.
 * @returns {Observable} an Observable that mirrors the source, but will call the specified function on termination.
 */
export function _finally<T>(finallySelector: () => void): Observable<T> {
  return this.lift(new FinallyOperator(finallySelector));
}
 
class FinallyOperator<T> implements Operator<T, T> {
  constructor(private finallySelector: () => void) {
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new FinallySubscriber(subscriber, this.finallySelector);
  }
}
 
class FinallySubscriber<T> extends Subscriber<T> {
  constructor(destination: Subscriber<T>, finallySelector: () => void) {
    super(destination);
    this.add(new Subscription(finallySelector));
  }
}