Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mergeScan.js 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /** PURE_IMPORTS_START tslib,_util_subscribeToResult,_OuterSubscriber,_InnerSubscriber PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { subscribeToResult } from '../util/subscribeToResult';
  4. import { OuterSubscriber } from '../OuterSubscriber';
  5. import { InnerSubscriber } from '../InnerSubscriber';
  6. export function mergeScan(accumulator, seed, concurrent) {
  7. if (concurrent === void 0) {
  8. concurrent = Number.POSITIVE_INFINITY;
  9. }
  10. return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
  11. }
  12. var MergeScanOperator = /*@__PURE__*/ (function () {
  13. function MergeScanOperator(accumulator, seed, concurrent) {
  14. this.accumulator = accumulator;
  15. this.seed = seed;
  16. this.concurrent = concurrent;
  17. }
  18. MergeScanOperator.prototype.call = function (subscriber, source) {
  19. return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
  20. };
  21. return MergeScanOperator;
  22. }());
  23. export { MergeScanOperator };
  24. var MergeScanSubscriber = /*@__PURE__*/ (function (_super) {
  25. tslib_1.__extends(MergeScanSubscriber, _super);
  26. function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
  27. var _this = _super.call(this, destination) || this;
  28. _this.accumulator = accumulator;
  29. _this.acc = acc;
  30. _this.concurrent = concurrent;
  31. _this.hasValue = false;
  32. _this.hasCompleted = false;
  33. _this.buffer = [];
  34. _this.active = 0;
  35. _this.index = 0;
  36. return _this;
  37. }
  38. MergeScanSubscriber.prototype._next = function (value) {
  39. if (this.active < this.concurrent) {
  40. var index = this.index++;
  41. var destination = this.destination;
  42. var ish = void 0;
  43. try {
  44. var accumulator = this.accumulator;
  45. ish = accumulator(this.acc, value, index);
  46. }
  47. catch (e) {
  48. return destination.error(e);
  49. }
  50. this.active++;
  51. this._innerSub(ish, value, index);
  52. }
  53. else {
  54. this.buffer.push(value);
  55. }
  56. };
  57. MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
  58. var innerSubscriber = new InnerSubscriber(this, undefined, undefined);
  59. var destination = this.destination;
  60. destination.add(innerSubscriber);
  61. subscribeToResult(this, ish, value, index, innerSubscriber);
  62. };
  63. MergeScanSubscriber.prototype._complete = function () {
  64. this.hasCompleted = true;
  65. if (this.active === 0 && this.buffer.length === 0) {
  66. if (this.hasValue === false) {
  67. this.destination.next(this.acc);
  68. }
  69. this.destination.complete();
  70. }
  71. this.unsubscribe();
  72. };
  73. MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  74. var destination = this.destination;
  75. this.acc = innerValue;
  76. this.hasValue = true;
  77. destination.next(innerValue);
  78. };
  79. MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
  80. var buffer = this.buffer;
  81. var destination = this.destination;
  82. destination.remove(innerSub);
  83. this.active--;
  84. if (buffer.length > 0) {
  85. this._next(buffer.shift());
  86. }
  87. else if (this.active === 0 && this.hasCompleted) {
  88. if (this.hasValue === false) {
  89. this.destination.next(this.acc);
  90. }
  91. this.destination.complete();
  92. }
  93. };
  94. return MergeScanSubscriber;
  95. }(OuterSubscriber));
  96. export { MergeScanSubscriber };
  97. //# sourceMappingURL=mergeScan.js.map