exhaust.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  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. * <img src="./img/exhaust.png" width="100%">
  12. *
  13. * `exhaust` 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. * `exhaust` 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 <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(5));
  24. * var result = higherOrder.exhaust();
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * @see {@link combineAll}
  28. * @see {@link concatAll}
  29. * @see {@link switch}
  30. * @see {@link mergeAll}
  31. * @see {@link exhaustMap}
  32. * @see {@link zipAll}
  33. *
  34. * @return {Observable} An Observable that takes a source of Observables and propagates the first observable
  35. * exclusively until it completes before subscribing to the next.
  36. */
  37. function exhaust() {
  38. return operators_1.exhaust()(this);
  39. }
  40. exports.exhaust = exhaust;
  41. //# sourceMappingURL=exhaust.js.map