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AE,CAAC;gBACnD,EAAE,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC;oBACrB,IAAI,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;oBAEzC,YAAY,CAAC,WAAW,EAAE,CAAC;oBAC3B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IACH,qBAAC;AAAD,CAAC,AArDD,CAAuC,iCAAe,GAqDrD;AArDY,sBAAc,iBAqD1B,CAAA","sourcesContent":["import { Observable } from '../Observable';\nimport { isArray } from '../util/isArray';\nimport { ArrayObservable } from '../observable/ArrayObservable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription, TeardownLogic } from '../Subscription';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\n\n/**\n * Returns an Observable that mirrors the first source Observable to emit an item.\n * @param {...Observables} ...observables sources used to race for which Observable emits first.\n * @return {Observable} an Observable that mirrors the output of the first Observable to emit an item.\n * @static true\n * @name race\n * @owner Observable\n */\nexport function race<T>(observables: Array<Observable<T>>): Observable<T>;\nexport function race<T>(observables: Array<Observable<any>>): Observable<T>;\nexport function race<T>(...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>;\nexport function race<T>(...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<T> {\n // if the only argument is an array, it was most likely called with\n // `race([obs1, obs2, ...])`\n if (observables.length === 1) {\n if (isArray(observables[0])) {\n observables = <Array<Observable<any>>>observables[0];\n } else {\n return <Observable<any>>observables[0];\n }\n }\n\n return new ArrayObservable<T>(<any>observables).lift(new RaceOperator<T>());\n}\n\nexport class RaceOperator<T> implements Operator<T, T> {\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new RaceSubscriber(subscriber));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class RaceSubscriber<T> extends OuterSubscriber<T, T> {\n private hasFirst: boolean = false;\n private observables: Observable<any>[] = [];\n private subscriptions: Subscription[] = [];\n\n constructor(destination: Subscriber<T>) {\n super(destination);\n }\n\n protected _next(observable: any): void {\n this.observables.push(observable);\n }\n\n protected _complete() {\n const observables = this.observables;\n const len = observables.length;\n\n if (len === 0) {\n this.destination.complete();\n } else {\n for (let i = 0; i < len && !this.hasFirst; i++) {\n let observable = observables[i];\n let subscription = subscribeToResult(this, observable, observable, i);\n\n if (this.subscriptions) {\n this.subscriptions.push(subscription);\n }\n this.add(subscription);\n }\n this.observables = null;\n }\n }\n\n notifyNext(outerValue: T, innerValue: T,\n outerIndex: number, innerIndex: number,\n innerSub: InnerSubscriber<T, T>): void {\n if (!this.hasFirst) {\n this.hasFirst = true;\n\n for (let i = 0; i < this.subscriptions.length; i++) {\n if (i !== outerIndex) {\n let subscription = this.subscriptions[i];\n\n subscription.unsubscribe();\n this.remove(subscription);\n }\n }\n\n this.subscriptions = null;\n }\n\n this.destination.next(innerValue);\n }\n}\n"]} |