onErrorResumeNext.js 3.3 KB

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