onErrorResumeNext.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { onErrorResumeNext as higherOrder } from '../operators/onErrorResumeNext';
  2. /* tslint:enable:max-line-length */
  3. /**
  4. * When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one
  5. * that was passed.
  6. *
  7. * <span class="informal">Execute series of Observables no matter what, even if it means swallowing errors.</span>
  8. *
  9. * <img src="./img/onErrorResumeNext.png" width="100%">
  10. *
  11. * `onErrorResumeNext` is an operator that accepts a series of Observables, provided either directly as
  12. * arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same
  13. * as the source.
  14. *
  15. * `onErrorResumeNext` returns an Observable that starts by subscribing and re-emitting values from the source Observable.
  16. * When its stream of values ends - no matter if Observable completed or emitted an error - `onErrorResumeNext`
  17. * will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting
  18. * its values as well and - again - when that stream ends, `onErrorResumeNext` will proceed to subscribing yet another
  19. * Observable in provided series, no matter if previous Observable completed or ended with an error. This will
  20. * be happening until there is no more Observables left in the series, at which point returned Observable will
  21. * complete - even if the last subscribed stream ended with an error.
  22. *
  23. * `onErrorResumeNext` can be therefore thought of as version of {@link concat} operator, which is more permissive
  24. * when it comes to the errors emitted by its input Observables. While `concat` subscribes to the next Observable
  25. * in series only if previous one successfully completed, `onErrorResumeNext` subscribes even if it ended with
  26. * an error.
  27. *
  28. * Note that you do not get any access to errors emitted by the Observables. In particular do not
  29. * expect these errors to appear in error callback passed to {@link subscribe}. If you want to take
  30. * specific actions based on what error was emitted by an Observable, you should try out {@link catch} instead.
  31. *
  32. *
  33. * @example <caption>Subscribe to the next Observable after map fails</caption>
  34. * Rx.Observable.of(1, 2, 3, 0)
  35. * .map(x => {
  36. * if (x === 0) { throw Error(); }
  37. return 10 / x;
  38. * })
  39. * .onErrorResumeNext(Rx.Observable.of(1, 2, 3))
  40. * .subscribe(
  41. * val => console.log(val),
  42. * err => console.log(err), // Will never be called.
  43. * () => console.log('that\'s it!')
  44. * );
  45. *
  46. * // Logs:
  47. * // 10
  48. * // 5
  49. * // 3.3333333333333335
  50. * // 1
  51. * // 2
  52. * // 3
  53. * // "that's it!"
  54. *
  55. * @see {@link concat}
  56. * @see {@link catch}
  57. *
  58. * @param {...ObservableInput} observables Observables passed either directly or as an array.
  59. * @return {Observable} An Observable that emits values from source Observable, but - if it errors - subscribes
  60. * to the next passed Observable and so on, until it completes or runs out of Observables.
  61. * @method onErrorResumeNext
  62. * @owner Observable
  63. */
  64. export function onErrorResumeNext(...nextSources) {
  65. return higherOrder(...nextSources)(this);
  66. }
  67. //# sourceMappingURL=onErrorResumeNext.js.map