import { isArray } from '../util/isArray'; import { fromArray } from './fromArray'; import { OuterSubscriber } from '../OuterSubscriber'; import { subscribeToResult } from '../util/subscribeToResult'; export function race(...observables) { if (observables.length === 1) { if (isArray(observables[0])) { observables = observables[0]; } else { return observables[0]; } } return fromArray(observables, undefined).lift(new RaceOperator()); } export class RaceOperator { call(subscriber, source) { return source.subscribe(new RaceSubscriber(subscriber)); } } export class RaceSubscriber extends OuterSubscriber { constructor(destination) { super(destination); this.hasFirst = false; this.observables = []; this.subscriptions = []; } _next(observable) { this.observables.push(observable); } _complete() { const observables = this.observables; const len = observables.length; if (len === 0) { this.destination.complete(); } else { for (let i = 0; i < len && !this.hasFirst; i++) { const observable = observables[i]; const subscription = subscribeToResult(this, observable, undefined, i); if (this.subscriptions) { this.subscriptions.push(subscription); } this.add(subscription); } this.observables = null; } } notifyNext(_outerValue, innerValue, outerIndex) { if (!this.hasFirst) { this.hasFirst = true; for (let i = 0; i < this.subscriptions.length; i++) { if (i !== outerIndex) { let subscription = this.subscriptions[i]; subscription.unsubscribe(); this.remove(subscription); } } this.subscriptions = null; } this.destination.next(innerValue); } } //# sourceMappingURL=race.js.map
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
dom | Folder | 0755 |
|
|
ConnectableObservable.js | File | 4.14 KB | 0644 |
|
ConnectableObservable.js.map | File | 3.82 KB | 0644 |
|
SubscribeOnObservable.js | File | 1.14 KB | 0644 |
|
SubscribeOnObservable.js.map | File | 1.2 KB | 0644 |
|
bindCallback.js | File | 2.82 KB | 0644 |
|
bindCallback.js.map | File | 2.83 KB | 0644 |
|
bindNodeCallback.js | File | 3.25 KB | 0644 |
|
bindNodeCallback.js.map | File | 3.23 KB | 0644 |
|
combineLatest.js | File | 2.82 KB | 0644 |
|
combineLatest.js.map | File | 2.86 KB | 0644 |
|
concat.js | File | 200 B | 0644 |
|
concat.js.map | File | 308 B | 0644 |
|
defer.js | File | 516 B | 0644 |
|
defer.js.map | File | 636 B | 0644 |
|
empty.js | File | 375 B | 0644 |
|
empty.js.map | File | 521 B | 0644 |
|
forkJoin.js | File | 2.2 KB | 0644 |
|
forkJoin.js.map | File | 2.43 KB | 0644 |
|
from.js | File | 441 B | 0644 |
|
from.js.map | File | 489 B | 0644 |
|
fromArray.js | File | 399 B | 0644 |
|
fromArray.js.map | File | 446 B | 0644 |
|
fromEvent.js | File | 2.45 KB | 0644 |
|
fromEvent.js.map | File | 2.53 KB | 0644 |
|
fromEventPattern.js | File | 926 B | 0644 |
|
fromEventPattern.js.map | File | 1.09 KB | 0644 |
|
fromIterable.js | File | 499 B | 0644 |
|
fromIterable.js.map | File | 529 B | 0644 |
|
fromPromise.js | File | 415 B | 0644 |
|
fromPromise.js.map | File | 450 B | 0644 |
|
generate.js | File | 3.39 KB | 0644 |
|
generate.js.map | File | 2.88 KB | 0644 |
|
iif.js | File | 237 B | 0644 |
|
iif.js.map | File | 364 B | 0644 |
|
interval.js | File | 758 B | 0644 |
|
interval.js.map | File | 945 B | 0644 |
|
merge.js | File | 901 B | 0644 |
|
merge.js.map | File | 995 B | 0644 |
|
never.js | File | 203 B | 0644 |
|
never.js.map | File | 307 B | 0644 |
|
of.js | File | 413 B | 0644 |
|
of.js.map | File | 511 B | 0644 |
|
onErrorResumeNext.js | File | 763 B | 0644 |
|
onErrorResumeNext.js.map | File | 941 B | 0644 |
|
pairs.js | File | 1.29 KB | 0644 |
|
pairs.js.map | File | 1.52 KB | 0644 |
|
partition.js | File | 441 B | 0644 |
|
partition.js.map | File | 562 B | 0644 |
|
race.js | File | 2.04 KB | 0644 |
|
race.js.map | File | 2.01 KB | 0644 |
|
range.js | File | 1.14 KB | 0644 |
|
range.js.map | File | 1.19 KB | 0644 |
|
throwError.js | File | 421 B | 0644 |
|
throwError.js.map | File | 565 B | 0644 |
|
timer.js | File | 1.12 KB | 0644 |
|
timer.js.map | File | 1.29 KB | 0644 |
|
using.js | File | 898 B | 0644 |
|
using.js.map | File | 939 B | 0644 |
|
zip.js | File | 5.7 KB | 0644 |
|
zip.js.map | File | 5.67 KB | 0644 |
|