d83ceb2a775650f382e628ceb54a0c36fa69eb205422f47c42f104a8fb133afc6ceb1ad9fe2da36e35a46dc214ad70d9e341f9dd4468bbaa29df17359a22cb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types';
  2. import { exhaustMap } from './exhaustMap';
  3. import { identity } from '../util/identity';
  4. /**
  5. * Converts a higher-order Observable into a first-order Observable by dropping
  6. * inner Observables while the previous inner Observable has not yet completed.
  7. *
  8. * <span class="informal">Flattens an Observable-of-Observables by dropping the
  9. * next inner Observables while the current inner is still executing.</span>
  10. *
  11. * ![](exhaustAll.svg)
  12. *
  13. * `exhaustAll` subscribes to an Observable that emits Observables, also known as a
  14. * higher-order Observable. Each time it observes one of these emitted inner
  15. * Observables, the output Observable begins emitting the items emitted by that
  16. * inner Observable. So far, it behaves like {@link mergeAll}. However,
  17. * `exhaustAll` ignores every new inner Observable if the previous Observable has
  18. * not yet completed. Once that one completes, it will accept and flatten the
  19. * next inner Observable and repeat this process.
  20. *
  21. * ## Example
  22. *
  23. * Run a finite timer for each click, only if there is no currently active timer
  24. *
  25. * ```ts
  26. * import { fromEvent, map, interval, take, exhaustAll } from 'rxjs';
  27. *
  28. * const clicks = fromEvent(document, 'click');
  29. * const higherOrder = clicks.pipe(
  30. * map(() => interval(1000).pipe(take(5)))
  31. * );
  32. * const result = higherOrder.pipe(exhaustAll());
  33. * result.subscribe(x => console.log(x));
  34. * ```
  35. *
  36. * @see {@link combineLatestAll}
  37. * @see {@link concatAll}
  38. * @see {@link switchAll}
  39. * @see {@link switchMap}
  40. * @see {@link mergeAll}
  41. * @see {@link exhaustMap}
  42. * @see {@link zipAll}
  43. *
  44. * @return A function that returns an Observable that takes a source of
  45. * Observables and propagates the first Observable exclusively until it
  46. * completes before subscribing to the next.
  47. */
  48. export function exhaustAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>> {
  49. return exhaustMap(identity);
  50. }