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

concatAll.ts 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { mergeAll } from './mergeAll';
  2. import { OperatorFunction, ObservableInput } from '../types';
  3. export function concatAll<T>(): OperatorFunction<ObservableInput<T>, T>;
  4. export function concatAll<R>(): OperatorFunction<any, R>;
  5. /**
  6. * Converts a higher-order Observable into a first-order Observable by
  7. * concatenating the inner Observables in order.
  8. *
  9. * <span class="informal">Flattens an Observable-of-Observables by putting one
  10. * inner Observable after the other.</span>
  11. *
  12. * ![](concatAll.png)
  13. *
  14. * Joins every Observable emitted by the source (a higher-order Observable), in
  15. * a serial fashion. It subscribes to each inner Observable only after the
  16. * previous inner Observable has completed, and merges all of their values into
  17. * the returned observable.
  18. *
  19. * __Warning:__ If the source Observable emits Observables quickly and
  20. * endlessly, and the inner Observables it emits generally complete slower than
  21. * the source emits, you can run into memory issues as the incoming Observables
  22. * collect in an unbounded buffer.
  23. *
  24. * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set
  25. * to `1`.
  26. *
  27. * ## Example
  28. *
  29. * For each click event, tick every second from 0 to 3, with no concurrency
  30. * ```ts
  31. * import { fromEvent, interval } from 'rxjs';
  32. * import { map, take, concatAll } from 'rxjs/operators';
  33. *
  34. * const clicks = fromEvent(document, 'click');
  35. * const higherOrder = clicks.pipe(
  36. * map(ev => interval(1000).pipe(take(4))),
  37. * );
  38. * const firstOrder = higherOrder.pipe(concatAll());
  39. * firstOrder.subscribe(x => console.log(x));
  40. *
  41. * // Results in the following:
  42. * // (results are not concurrent)
  43. * // For every click on the "document" it will emit values 0 to 3 spaced
  44. * // on a 1000ms interval
  45. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  46. * ```
  47. *
  48. * @see {@link combineAll}
  49. * @see {@link concat}
  50. * @see {@link concatMap}
  51. * @see {@link concatMapTo}
  52. * @see {@link exhaust}
  53. * @see {@link mergeAll}
  54. * @see {@link switchAll}
  55. * @see {@link switchMap}
  56. * @see {@link zipAll}
  57. *
  58. * @return {Observable} An Observable emitting values from all the inner
  59. * Observables concatenated.
  60. * @method concatAll
  61. * @owner Observable
  62. */
  63. export function concatAll<T>(): OperatorFunction<ObservableInput<T>, T> {
  64. return mergeAll<T>(1);
  65. }