Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

concat.ts 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { Observable } from '../Observable';
  2. import { ObservableInput, SchedulerLike, ObservedValueOf } from '../types';
  3. import { isScheduler } from '../util/isScheduler';
  4. import { of } from './of';
  5. import { from } from './from';
  6. import { concatAll } from '../operators/concatAll';
  7. /* tslint:disable:max-line-length */
  8. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  9. export function concat<O1 extends ObservableInput<any>>(v1: O1, scheduler: SchedulerLike): Observable<ObservedValueOf<O1>>;
  10. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  11. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>>(v1: O1, v2: O2, scheduler: SchedulerLike): Observable<ObservedValueOf<O1> | ObservedValueOf<O2>>;
  12. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  13. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, scheduler: SchedulerLike): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3>>;
  14. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  15. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4, scheduler: SchedulerLike): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4>>;
  16. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  17. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>, O5 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, scheduler: SchedulerLike): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4> | ObservedValueOf<O5>>;
  18. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  19. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>, O5 extends ObservableInput<any>, O6 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, scheduler: SchedulerLike): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4> | ObservedValueOf<O5> | ObservedValueOf<O6>>;
  20. export function concat<O1 extends ObservableInput<any>>(v1: O1): Observable<ObservedValueOf<O1>>;
  21. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>>(v1: O1, v2: O2): Observable<ObservedValueOf<O1> | ObservedValueOf<O2>>;
  22. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3>>;
  23. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4>>;
  24. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>, O5 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4> | ObservedValueOf<O5>>;
  25. export function concat<O1 extends ObservableInput<any>, O2 extends ObservableInput<any>, O3 extends ObservableInput<any>, O4 extends ObservableInput<any>, O5 extends ObservableInput<any>, O6 extends ObservableInput<any>>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6): Observable<ObservedValueOf<O1> | ObservedValueOf<O2> | ObservedValueOf<O3> | ObservedValueOf<O4> | ObservedValueOf<O5> | ObservedValueOf<O6>>;
  26. export function concat<O extends ObservableInput<any>>(...observables: O[]): Observable<ObservedValueOf<O>>;
  27. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  28. export function concat<O extends ObservableInput<any>>(...observables: (O | SchedulerLike)[]): Observable<ObservedValueOf<O>>;
  29. export function concat<R>(...observables: ObservableInput<any>[]): Observable<R>;
  30. /** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */
  31. export function concat<R>(...observables: (ObservableInput<any> | SchedulerLike)[]): Observable<R>;
  32. /* tslint:enable:max-line-length */
  33. /**
  34. * Creates an output Observable which sequentially emits all values from given
  35. * Observable and then moves on to the next.
  36. *
  37. * <span class="informal">Concatenates multiple Observables together by
  38. * sequentially emitting their values, one Observable after the other.</span>
  39. *
  40. * ![](concat.png)
  41. *
  42. * `concat` joins multiple Observables together, by subscribing to them one at a time and
  43. * merging their results into the output Observable. You can pass either an array of
  44. * Observables, or put them directly as arguments. Passing an empty array will result
  45. * in Observable that completes immediately.
  46. *
  47. * `concat` will subscribe to first input Observable and emit all its values, without
  48. * changing or affecting them in any way. When that Observable completes, it will
  49. * subscribe to then next Observable passed and, again, emit its values. This will be
  50. * repeated, until the operator runs out of Observables. When last input Observable completes,
  51. * `concat` will complete as well. At any given moment only one Observable passed to operator
  52. * emits values. If you would like to emit values from passed Observables concurrently, check out
  53. * {@link merge} instead, especially with optional `concurrent` parameter. As a matter of fact,
  54. * `concat` is an equivalent of `merge` operator with `concurrent` parameter set to `1`.
  55. *
  56. * Note that if some input Observable never completes, `concat` will also never complete
  57. * and Observables following the one that did not complete will never be subscribed. On the other
  58. * hand, if some Observable simply completes immediately after it is subscribed, it will be
  59. * invisible for `concat`, which will just move on to the next Observable.
  60. *
  61. * If any Observable in chain errors, instead of passing control to the next Observable,
  62. * `concat` will error immediately as well. Observables that would be subscribed after
  63. * the one that emitted error, never will.
  64. *
  65. * If you pass to `concat` the same Observable many times, its stream of values
  66. * will be "replayed" on every subscription, which means you can repeat given Observable
  67. * as many times as you like. If passing the same Observable to `concat` 1000 times becomes tedious,
  68. * you can always use {@link repeat}.
  69. *
  70. * ## Examples
  71. * ### Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10
  72. * ```ts
  73. * import { concat, interval, range } from 'rxjs';
  74. * import { take } from 'rxjs/operators';
  75. *
  76. * const timer = interval(1000).pipe(take(4));
  77. * const sequence = range(1, 10);
  78. * const result = concat(timer, sequence);
  79. * result.subscribe(x => console.log(x));
  80. *
  81. * // results in:
  82. * // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
  83. * ```
  84. *
  85. * ### Concatenate 3 Observables
  86. * ```ts
  87. * import { concat, interval } from 'rxjs';
  88. * import { take } from 'rxjs/operators';
  89. *
  90. * const timer1 = interval(1000).pipe(take(10));
  91. * const timer2 = interval(2000).pipe(take(6));
  92. * const timer3 = interval(500).pipe(take(10));
  93. *
  94. * const result = concat(timer1, timer2, timer3);
  95. * result.subscribe(x => console.log(x));
  96. *
  97. * // results in the following:
  98. * // (Prints to console sequentially)
  99. * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
  100. * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
  101. * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
  102. * ```
  103. *
  104. * ### Concatenate the same Observable to repeat it
  105. * ```ts
  106. * import { concat, interval } from 'rxjs';
  107. * import { take } from 'rxjs/operators';
  108. *
  109. * const timer = interval(1000).pipe(take(2));
  110. *
  111. * concat(timer, timer) // concatenating the same Observable!
  112. * .subscribe(
  113. * value => console.log(value),
  114. * err => {},
  115. * () => console.log('...and it is done!')
  116. * );
  117. *
  118. * // Logs:
  119. * // 0 after 1s
  120. * // 1 after 2s
  121. * // 0 after 3s
  122. * // 1 after 4s
  123. * // "...and it is done!" also after 4s
  124. * ```
  125. *
  126. * @see {@link concatAll}
  127. * @see {@link concatMap}
  128. * @see {@link concatMapTo}
  129. * @see {@link startWith}
  130. * @see {@link endWith}
  131. *
  132. * @param {ObservableInput} input1 An input Observable to concatenate with others.
  133. * @param {ObservableInput} input2 An input Observable to concatenate with others.
  134. * More than one input Observables may be given as argument.
  135. * @param {SchedulerLike} [scheduler=null] An optional {@link SchedulerLike} to schedule each
  136. * Observable subscription on.
  137. * @return {Observable} All values of each passed Observable merged into a
  138. * single Observable, in order, in serial fashion.
  139. * @static true
  140. * @name concat
  141. * @owner Observable
  142. */
  143. export function concat<O extends ObservableInput<any>, R>(...observables: Array<O | SchedulerLike>): Observable<ObservedValueOf<O> | R> {
  144. return concatAll<R>()(of(...observables));
  145. }