421d031aaad2c51c69587a44ae47d25b1e95349fcea5b44fdd7bc65a2414ded6b9fa824a339302075f3f057decb0b83bf2bc2975b66d58b0a3c79c0efb12e1 2.1 KB

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