Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829303132333435363738
  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. * Returns an Observable that mirrors the source Observable, but will call a specified function when
  8. * the source terminates on complete or error.
  9. * @param {function} callback Function to be called when source terminates.
  10. * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.
  11. * @method finally
  12. * @owner Observable
  13. */
  14. export function finalize<T>(callback: () => void): MonoTypeOperatorFunction<T> {
  15. return (source: Observable<T>) => source.lift(new FinallyOperator(callback));
  16. }
  17. class FinallyOperator<T> implements Operator<T, T> {
  18. constructor(private callback: () => void) {
  19. }
  20. call(subscriber: Subscriber<T>, source: any): TeardownLogic {
  21. return source.subscribe(new FinallySubscriber(subscriber, this.callback));
  22. }
  23. }
  24. /**
  25. * We need this JSDoc comment for affecting ESDoc.
  26. * @ignore
  27. * @extends {Ignored}
  28. */
  29. class FinallySubscriber<T> extends Subscriber<T> {
  30. constructor(destination: Subscriber<T>, callback: () => void) {
  31. super(destination);
  32. this.add(new Subscription(callback));
  33. }
  34. }