source: trip-planner-front/node_modules/rxjs/src/internal/observable/merge.ts

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

initial commit

  • Property mode set to 100644
File size: 9.9 KB
Line 
1import { Observable } from '../Observable';
2import { ObservableInput, SchedulerLike} from '../types';
3import { isScheduler } from '../util/isScheduler';
4import { mergeAll } from '../operators/mergeAll';
5import { fromArray } from './fromArray';
6
7/* tslint:disable:max-line-length */
8/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
9export function merge<T>(v1: ObservableInput<T>, scheduler: SchedulerLike): Observable<T>;
10/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
11export function merge<T>(v1: ObservableInput<T>, concurrent: number, scheduler: SchedulerLike): Observable<T>;
12/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
13export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, scheduler: SchedulerLike): Observable<T | T2>;
14/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
15export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, concurrent: number, scheduler: SchedulerLike): Observable<T | T2>;
16/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
17export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, scheduler: SchedulerLike): Observable<T | T2 | T3>;
18/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
19export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, concurrent: number, scheduler: SchedulerLike): Observable<T | T2 | T3>;
20/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
21export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4>;
22/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
23export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, concurrent: number, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4>;
24/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
25export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4 | T5>;
26/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
27export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, concurrent: number, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4 | T5>;
28/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
29export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4 | T5 | T6>;
30/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
31export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, concurrent: number, scheduler: SchedulerLike): Observable<T | T2 | T3 | T4 | T5 | T6>;
32
33export function merge<T>(v1: ObservableInput<T>): Observable<T>;
34export function merge<T>(v1: ObservableInput<T>, concurrent?: number): Observable<T>;
35export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>): Observable<T | T2>;
36export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, concurrent?: number): Observable<T | T2>;
37export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>): Observable<T | T2 | T3>;
38export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, concurrent?: number): Observable<T | T2 | T3>;
39export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>): Observable<T | T2 | T3 | T4>;
40export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, concurrent?: number): Observable<T | T2 | T3 | T4>;
41export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>): Observable<T | T2 | T3 | T4 | T5>;
42export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, concurrent?: number): Observable<T | T2 | T3 | T4 | T5>;
43export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>): Observable<T | T2 | T3 | T4 | T5 | T6>;
44export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, concurrent?: number): Observable<T | T2 | T3 | T4 | T5 | T6>;
45export function merge<T>(...observables: (ObservableInput<T> | number)[]): Observable<T>;
46/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
47export function merge<T>(...observables: (ObservableInput<T> | SchedulerLike | number)[]): Observable<T>;
48export function merge<T, R>(...observables: (ObservableInput<any> | number)[]): Observable<R>;
49/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/
50export function merge<T, R>(...observables: (ObservableInput<any> | SchedulerLike | number)[]): Observable<R>;
51/* tslint:enable:max-line-length */
52/**
53 * Creates an output Observable which concurrently emits all values from every
54 * given input Observable.
55 *
56 * <span class="informal">Flattens multiple Observables together by blending
57 * their values into one Observable.</span>
58 *
59 * ![](merge.png)
60 *
61 * `merge` subscribes to each given input Observable (as arguments), and simply
62 * forwards (without doing any transformation) all the values from all the input
63 * Observables to the output Observable. The output Observable only completes
64 * once all input Observables have completed. Any error delivered by an input
65 * Observable will be immediately emitted on the output Observable.
66 *
67 * ## Examples
68 * ### Merge together two Observables: 1s interval and clicks
69 * ```ts
70 * import { merge, fromEvent, interval } from 'rxjs';
71 *
72 * const clicks = fromEvent(document, 'click');
73 * const timer = interval(1000);
74 * const clicksOrTimer = merge(clicks, timer);
75 * clicksOrTimer.subscribe(x => console.log(x));
76 *
77 * // Results in the following:
78 * // timer will emit ascending values, one every second(1000ms) to console
79 * // clicks logs MouseEvents to console everytime the "document" is clicked
80 * // Since the two streams are merged you see these happening
81 * // as they occur.
82 * ```
83 *
84 * ### Merge together 3 Observables, but only 2 run concurrently
85 * ```ts
86 * import { merge, interval } from 'rxjs';
87 * import { take } from 'rxjs/operators';
88 *
89 * const timer1 = interval(1000).pipe(take(10));
90 * const timer2 = interval(2000).pipe(take(6));
91 * const timer3 = interval(500).pipe(take(10));
92 * const concurrent = 2; // the argument
93 * const merged = merge(timer1, timer2, timer3, concurrent);
94 * merged.subscribe(x => console.log(x));
95 *
96 * // Results in the following:
97 * // - First timer1 and timer2 will run concurrently
98 * // - timer1 will emit a value every 1000ms for 10 iterations
99 * // - timer2 will emit a value every 2000ms for 6 iterations
100 * // - after timer1 hits its max iteration, timer2 will
101 * // continue, and timer3 will start to run concurrently with timer2
102 * // - when timer2 hits its max iteration it terminates, and
103 * // timer3 will continue to emit a value every 500ms until it is complete
104 * ```
105 *
106 * @see {@link mergeAll}
107 * @see {@link mergeMap}
108 * @see {@link mergeMapTo}
109 * @see {@link mergeScan}
110 *
111 * @param {...ObservableInput} observables Input Observables to merge together.
112 * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
113 * Observables being subscribed to concurrently.
114 * @param {SchedulerLike} [scheduler=null] The {@link SchedulerLike} to use for managing
115 * concurrency of input Observables.
116 * @return {Observable} an Observable that emits items that are the result of
117 * every input Observable.
118 * @static true
119 * @name merge
120 * @owner Observable
121 */
122export function merge<T, R>(...observables: Array<ObservableInput<any> | SchedulerLike | number>): Observable<R> {
123 let concurrent = Number.POSITIVE_INFINITY;
124 let scheduler: SchedulerLike = null;
125 let last: any = observables[observables.length - 1];
126 if (isScheduler(last)) {
127 scheduler = <SchedulerLike>observables.pop();
128 if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
129 concurrent = <number>observables.pop();
130 }
131 } else if (typeof last === 'number') {
132 concurrent = <number>observables.pop();
133 }
134
135 if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
136 return <Observable<R>>observables[0];
137 }
138
139 return mergeAll<R>(concurrent)(fromArray<any>(observables, scheduler));
140}
Note: See TracBrowser for help on using the repository browser.