source: trip-planner-front/node_modules/rxjs/_esm2015/internal/observable/race.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { isArray } from '../util/isArray';
2import { fromArray } from './fromArray';
3import { OuterSubscriber } from '../OuterSubscriber';
4import { subscribeToResult } from '../util/subscribeToResult';
5export function race(...observables) {
6 if (observables.length === 1) {
7 if (isArray(observables[0])) {
8 observables = observables[0];
9 }
10 else {
11 return observables[0];
12 }
13 }
14 return fromArray(observables, undefined).lift(new RaceOperator());
15}
16export class RaceOperator {
17 call(subscriber, source) {
18 return source.subscribe(new RaceSubscriber(subscriber));
19 }
20}
21export class RaceSubscriber extends OuterSubscriber {
22 constructor(destination) {
23 super(destination);
24 this.hasFirst = false;
25 this.observables = [];
26 this.subscriptions = [];
27 }
28 _next(observable) {
29 this.observables.push(observable);
30 }
31 _complete() {
32 const observables = this.observables;
33 const len = observables.length;
34 if (len === 0) {
35 this.destination.complete();
36 }
37 else {
38 for (let i = 0; i < len && !this.hasFirst; i++) {
39 const observable = observables[i];
40 const subscription = subscribeToResult(this, observable, undefined, i);
41 if (this.subscriptions) {
42 this.subscriptions.push(subscription);
43 }
44 this.add(subscription);
45 }
46 this.observables = null;
47 }
48 }
49 notifyNext(_outerValue, innerValue, outerIndex) {
50 if (!this.hasFirst) {
51 this.hasFirst = true;
52 for (let i = 0; i < this.subscriptions.length; i++) {
53 if (i !== outerIndex) {
54 let subscription = this.subscriptions[i];
55 subscription.unsubscribe();
56 this.remove(subscription);
57 }
58 }
59 this.subscriptions = null;
60 }
61 this.destination.next(innerValue);
62 }
63}
64//# sourceMappingURL=race.js.map
Note: See TracBrowser for help on using the repository browser.