import { Observable, ObservableInput } from '../Observable'; import { FromObservable } from '../observable/FromObservable'; import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { isArray } from '../util/isArray'; import { OuterSubscriber } from '../OuterSubscriber'; import { InnerSubscriber } from '../InnerSubscriber'; import { subscribeToResult } from '../util/subscribeToResult'; /* tslint:disable:max-line-length */ export function onErrorResumeNext(this: Observable, v: ObservableInput): Observable; export function onErrorResumeNext(this: Observable, v2: ObservableInput, v3: ObservableInput): Observable; export function onErrorResumeNext(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput): Observable; export function onErrorResumeNext(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput): Observable; export function onErrorResumeNext(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput): Observable ; export function onErrorResumeNext(this: Observable, ...observables: Array | ((...values: Array) => R)>): Observable; export function onErrorResumeNext(this: Observable, array: ObservableInput[]): Observable; /* tslint:disable:max-line-length */ export function onErrorResumeNext(this: Observable, ...nextSources: Array | Array> | ((...values: Array) => R)>): Observable { if (nextSources.length === 1 && isArray(nextSources[0])) { nextSources = >>nextSources[0]; } return this.lift(new OnErrorResumeNextOperator(nextSources)); } /* tslint:disable:max-line-length */ export function onErrorResumeNextStatic(v: ObservableInput): Observable; export function onErrorResumeNextStatic(v2: ObservableInput, v3: ObservableInput): Observable; export function onErrorResumeNextStatic(v2: ObservableInput, v3: ObservableInput, v4: ObservableInput): Observable; export function onErrorResumeNextStatic(v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput): Observable; export function onErrorResumeNextStatic(v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput): Observable; export function onErrorResumeNextStatic(...observables: Array | ((...values: Array) => R)>): Observable; export function onErrorResumeNextStatic(array: ObservableInput[]): Observable; /* tslint:enable:max-line-length */ export function onErrorResumeNextStatic(...nextSources: Array | Array> | ((...values: Array) => R)>): Observable { let source: ObservableInput = null; if (nextSources.length === 1 && isArray(nextSources[0])) { nextSources = >>nextSources[0]; } source = nextSources.shift(); return new FromObservable(source, null).lift(new OnErrorResumeNextOperator(nextSources)); } class OnErrorResumeNextOperator implements Operator { constructor(private nextSources: Array>) { } call(subscriber: Subscriber, source: any): any { return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources)); } } class OnErrorResumeNextSubscriber extends OuterSubscriber { constructor(protected destination: Subscriber, private nextSources: Array>) { super(destination); } notifyError(error: any, innerSub: InnerSubscriber): void { this.subscribeToNextSource(); } notifyComplete(innerSub: InnerSubscriber): void { this.subscribeToNextSource(); } protected _error(err: any): void { this.subscribeToNextSource(); } protected _complete(): void { this.subscribeToNextSource(); } private subscribeToNextSource(): void { const next = this.nextSources.shift(); if (next) { this.add(subscribeToResult(this, next)); } else { this.destination.complete(); } } }