123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /** PURE_IMPORTS_START .._observable_FromObservable,.._util_isArray,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */
- var __extends = (this && this.__extends) || function (d, b) {
- for (var p in b)
- if (b.hasOwnProperty(p))
- d[p] = b[p];
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- import { FromObservable } from '../observable/FromObservable';
- import { isArray } from '../util/isArray';
- import { OuterSubscriber } from '../OuterSubscriber';
- import { subscribeToResult } from '../util/subscribeToResult';
- /* tslint:enable:max-line-length */
- /**
- * When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one
- * that was passed.
- *
- * <span class="informal">Execute series of Observables no matter what, even if it means swallowing errors.</span>
- *
- * <img src="./img/onErrorResumeNext.png" width="100%">
- *
- * `onErrorResumeNext` is an operator that accepts a series of Observables, provided either directly as
- * arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same
- * as the source.
- *
- * `onErrorResumeNext` returns an Observable that starts by subscribing and re-emitting values from the source Observable.
- * When its stream of values ends - no matter if Observable completed or emitted an error - `onErrorResumeNext`
- * will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting
- * its values as well and - again - when that stream ends, `onErrorResumeNext` will proceed to subscribing yet another
- * Observable in provided series, no matter if previous Observable completed or ended with an error. This will
- * be happening until there is no more Observables left in the series, at which point returned Observable will
- * complete - even if the last subscribed stream ended with an error.
- *
- * `onErrorResumeNext` can be therefore thought of as version of {@link concat} operator, which is more permissive
- * when it comes to the errors emitted by its input Observables. While `concat` subscribes to the next Observable
- * in series only if previous one successfully completed, `onErrorResumeNext` subscribes even if it ended with
- * an error.
- *
- * Note that you do not get any access to errors emitted by the Observables. In particular do not
- * expect these errors to appear in error callback passed to {@link subscribe}. If you want to take
- * specific actions based on what error was emitted by an Observable, you should try out {@link catch} instead.
- *
- *
- * @example <caption>Subscribe to the next Observable after map fails</caption>
- * Rx.Observable.of(1, 2, 3, 0)
- * .map(x => {
- * if (x === 0) { throw Error(); }
- return 10 / x;
- * })
- * .onErrorResumeNext(Rx.Observable.of(1, 2, 3))
- * .subscribe(
- * val => console.log(val),
- * err => console.log(err), // Will never be called.
- * () => console.log('that\'s it!')
- * );
- *
- * // Logs:
- * // 10
- * // 5
- * // 3.3333333333333335
- * // 1
- * // 2
- * // 3
- * // "that's it!"
- *
- * @see {@link concat}
- * @see {@link catch}
- *
- * @param {...ObservableInput} observables Observables passed either directly or as an array.
- * @return {Observable} An Observable that emits values from source Observable, but - if it errors - subscribes
- * to the next passed Observable and so on, until it completes or runs out of Observables.
- * @method onErrorResumeNext
- * @owner Observable
- */
- export function onErrorResumeNext() {
- var nextSources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nextSources[_i - 0] = arguments[_i];
- }
- if (nextSources.length === 1 && isArray(nextSources[0])) {
- nextSources = nextSources[0];
- }
- return function (source) { return source.lift(new OnErrorResumeNextOperator(nextSources)); };
- }
- /* tslint:enable:max-line-length */
- export function onErrorResumeNextStatic() {
- var nextSources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nextSources[_i - 0] = arguments[_i];
- }
- var source = null;
- if (nextSources.length === 1 && isArray(nextSources[0])) {
- nextSources = nextSources[0];
- }
- source = nextSources.shift();
- return new FromObservable(source, null).lift(new OnErrorResumeNextOperator(nextSources));
- }
- var OnErrorResumeNextOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
- function OnErrorResumeNextOperator(nextSources) {
- this.nextSources = nextSources;
- }
- OnErrorResumeNextOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources));
- };
- return OnErrorResumeNextOperator;
- }());
- var OnErrorResumeNextSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
- __extends(OnErrorResumeNextSubscriber, _super);
- function OnErrorResumeNextSubscriber(destination, nextSources) {
- _super.call(this, destination);
- this.destination = destination;
- this.nextSources = nextSources;
- }
- OnErrorResumeNextSubscriber.prototype.notifyError = function (error, innerSub) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype.notifyComplete = function (innerSub) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype._error = function (err) {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype._complete = function () {
- this.subscribeToNextSource();
- };
- OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () {
- var next = this.nextSources.shift();
- if (next) {
- this.add(subscribeToResult(this, next));
- }
- else {
- this.destination.complete();
- }
- };
- return OnErrorResumeNextSubscriber;
- }(OuterSubscriber));
- //# sourceMappingURL=onErrorResumeNext.js.map
|