a zip code crypto-currency system good for red ONLY

exhaust.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /** PURE_IMPORTS_START .._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { OuterSubscriber } from '../OuterSubscriber';
  10. import { subscribeToResult } from '../util/subscribeToResult';
  11. /**
  12. * Converts a higher-order Observable into a first-order Observable by dropping
  13. * inner Observables while the previous inner Observable has not yet completed.
  14. *
  15. * <span class="informal">Flattens an Observable-of-Observables by dropping the
  16. * next inner Observables while the current inner is still executing.</span>
  17. *
  18. * <img src="./img/exhaust.png" width="100%">
  19. *
  20. * `exhaust` subscribes to an Observable that emits Observables, also known as a
  21. * higher-order Observable. Each time it observes one of these emitted inner
  22. * Observables, the output Observable begins emitting the items emitted by that
  23. * inner Observable. So far, it behaves like {@link mergeAll}. However,
  24. * `exhaust` ignores every new inner Observable if the previous Observable has
  25. * not yet completed. Once that one completes, it will accept and flatten the
  26. * next inner Observable and repeat this process.
  27. *
  28. * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
  29. * var clicks = Rx.Observable.fromEvent(document, 'click');
  30. * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(5));
  31. * var result = higherOrder.exhaust();
  32. * result.subscribe(x => console.log(x));
  33. *
  34. * @see {@link combineAll}
  35. * @see {@link concatAll}
  36. * @see {@link switch}
  37. * @see {@link mergeAll}
  38. * @see {@link exhaustMap}
  39. * @see {@link zipAll}
  40. *
  41. * @return {Observable} An Observable that takes a source of Observables and propagates the first observable
  42. * exclusively until it completes before subscribing to the next.
  43. * @method exhaust
  44. * @owner Observable
  45. */
  46. export function exhaust() {
  47. return function (source) { return source.lift(new SwitchFirstOperator()); };
  48. }
  49. var SwitchFirstOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  50. function SwitchFirstOperator() {
  51. }
  52. SwitchFirstOperator.prototype.call = function (subscriber, source) {
  53. return source.subscribe(new SwitchFirstSubscriber(subscriber));
  54. };
  55. return SwitchFirstOperator;
  56. }());
  57. /**
  58. * We need this JSDoc comment for affecting ESDoc.
  59. * @ignore
  60. * @extends {Ignored}
  61. */
  62. var SwitchFirstSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  63. __extends(SwitchFirstSubscriber, _super);
  64. function SwitchFirstSubscriber(destination) {
  65. _super.call(this, destination);
  66. this.hasCompleted = false;
  67. this.hasSubscription = false;
  68. }
  69. SwitchFirstSubscriber.prototype._next = function (value) {
  70. if (!this.hasSubscription) {
  71. this.hasSubscription = true;
  72. this.add(subscribeToResult(this, value));
  73. }
  74. };
  75. SwitchFirstSubscriber.prototype._complete = function () {
  76. this.hasCompleted = true;
  77. if (!this.hasSubscription) {
  78. this.destination.complete();
  79. }
  80. };
  81. SwitchFirstSubscriber.prototype.notifyComplete = function (innerSub) {
  82. this.remove(innerSub);
  83. this.hasSubscription = false;
  84. if (this.hasCompleted) {
  85. this.destination.complete();
  86. }
  87. };
  88. return SwitchFirstSubscriber;
  89. }(OuterSubscriber));
  90. //# sourceMappingURL=exhaust.js.map