962227a7417e0c085878598a58c63c8fdf24232687fd6794b6f0e646079ee7d9ce8fd5f7a9f0a4a516926cf9d35aaa85306020c7ae8b1717066027efd47d1c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { 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 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. */
  63. export declare function finalize<T>(callback: () => void): MonoTypeOperatorFunction<T>;
  64. //# sourceMappingURL=finalize.d.ts.map