import { Observable, ObservableInput } from '../Observable'; import { Scheduler } from '../Scheduler'; import { isScheduler } from '../util/isScheduler'; import { ArrayObservable } from '../observable/ArrayObservable'; import { MergeAllOperator } from './mergeAll'; /* tslint:disable:max-line-length */ export function concat(this: Observable, scheduler?: Scheduler): Observable; export function concat(this: Observable, v2: ObservableInput, scheduler?: Scheduler): Observable; export function concat(this: Observable, v2: ObservableInput, v3: ObservableInput, scheduler?: Scheduler): Observable; export function concat(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, scheduler?: Scheduler): Observable; export function concat(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, scheduler?: Scheduler): Observable; export function concat(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, scheduler?: Scheduler): Observable; export function concat(this: Observable, ...observables: Array | Scheduler>): Observable; export function concat(this: Observable, ...observables: Array | Scheduler>): Observable; /* tslint:disable:max-line-length */ /** * Creates an output Observable which sequentially emits all values from every * given input Observable after the current Observable. * * Concatenates multiple Observables together by * sequentially emitting their values, one Observable after the other. * * * * Joins this Observable with multiple other Observables by subscribing to them * one at a time, starting with the source, and merging their results into the * output Observable. Will wait for each Observable to complete before moving * on to the next. * * @example Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 * var timer = Rx.Observable.interval(1000).take(4); * var sequence = Rx.Observable.range(1, 10); * var result = timer.concat(sequence); * result.subscribe(x => console.log(x)); * * // results in: * // 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10 * * @example Concatenate 3 Observables * var timer1 = Rx.Observable.interval(1000).take(10); * var timer2 = Rx.Observable.interval(2000).take(6); * var timer3 = Rx.Observable.interval(500).take(10); * var result = timer1.concat(timer2, timer3); * result.subscribe(x => console.log(x)); * * // results in the following: * // (Prints to console sequentially) * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9 * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5 * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9 * * @see {@link concatAll} * @see {@link concatMap} * @see {@link concatMapTo} * * @param {Observable} other An input Observable to concatenate after the source * Observable. More than one input Observables may be given as argument. * @param {Scheduler} [scheduler=null] An optional Scheduler to schedule each * Observable subscription on. * @return {Observable} All values of each passed Observable merged into a * single Observable, in order, in serial fashion. * @method concat * @owner Observable */ export function concat(this: Observable, ...observables: Array | Scheduler>): Observable { return this.lift.call(concatStatic(this, ...observables)); } /* tslint:disable:max-line-length */ export function concatStatic(v1: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(v1: ObservableInput, v2: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, scheduler?: Scheduler): Observable; export function concatStatic(...observables: (ObservableInput | Scheduler)[]): Observable; export function concatStatic(...observables: (ObservableInput | Scheduler)[]): Observable; /* tslint:enable:max-line-length */ /** * Creates an output Observable which sequentially emits all values from every * given input Observable after the current Observable. * * Concatenates multiple Observables together by * sequentially emitting their values, one Observable after the other. * * * * Joins multiple Observables together by subscribing to them one at a time and * merging their results into the output Observable. Will wait for each * Observable to complete before moving on to the next. * * @example Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 * var timer = Rx.Observable.interval(1000).take(4); * var sequence = Rx.Observable.range(1, 10); * var result = Rx.Observable.concat(timer, sequence); * result.subscribe(x => console.log(x)); * * // results in: * // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10 * * @example Concatenate 3 Observables * var timer1 = Rx.Observable.interval(1000).take(10); * var timer2 = Rx.Observable.interval(2000).take(6); * var timer3 = Rx.Observable.interval(500).take(10); * var result = Rx.Observable.concat(timer1, timer2, timer3); * result.subscribe(x => console.log(x)); * * // results in the following: * // (Prints to console sequentially) * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9 * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5 * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9 * * @see {@link concatAll} * @see {@link concatMap} * @see {@link concatMapTo} * * @param {Observable} input1 An input Observable to concatenate with others. * @param {Observable} input2 An input Observable to concatenate with others. * More than one input Observables may be given as argument. * @param {Scheduler} [scheduler=null] An optional Scheduler to schedule each * Observable subscription on. * @return {Observable} All values of each passed Observable merged into a * single Observable, in order, in serial fashion. * @static true * @name concat * @owner Observable */ export function concatStatic(...observables: Array | Scheduler>): Observable { let scheduler: Scheduler = null; let args = observables; if (isScheduler(args[observables.length - 1])) { scheduler = args.pop(); } if (scheduler === null && observables.length === 1) { return >observables[0]; } return new ArrayObservable(observables, scheduler).lift(new MergeAllOperator(1)); }