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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var subscribeToResult_1 = require("../util/subscribeToResult");
  17. var OuterSubscriber_1 = require("../OuterSubscriber");
  18. var InnerSubscriber_1 = require("../InnerSubscriber");
  19. function mergeScan(accumulator, seed, concurrent) {
  20. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  21. return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
  22. }
  23. exports.mergeScan = mergeScan;
  24. var MergeScanOperator = (function () {
  25. function MergeScanOperator(accumulator, seed, concurrent) {
  26. this.accumulator = accumulator;
  27. this.seed = seed;
  28. this.concurrent = concurrent;
  29. }
  30. MergeScanOperator.prototype.call = function (subscriber, source) {
  31. return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
  32. };
  33. return MergeScanOperator;
  34. }());
  35. exports.MergeScanOperator = MergeScanOperator;
  36. var MergeScanSubscriber = (function (_super) {
  37. __extends(MergeScanSubscriber, _super);
  38. function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
  39. var _this = _super.call(this, destination) || this;
  40. _this.accumulator = accumulator;
  41. _this.acc = acc;
  42. _this.concurrent = concurrent;
  43. _this.hasValue = false;
  44. _this.hasCompleted = false;
  45. _this.buffer = [];
  46. _this.active = 0;
  47. _this.index = 0;
  48. return _this;
  49. }
  50. MergeScanSubscriber.prototype._next = function (value) {
  51. if (this.active < this.concurrent) {
  52. var index = this.index++;
  53. var destination = this.destination;
  54. var ish = void 0;
  55. try {
  56. var accumulator = this.accumulator;
  57. ish = accumulator(this.acc, value, index);
  58. }
  59. catch (e) {
  60. return destination.error(e);
  61. }
  62. this.active++;
  63. this._innerSub(ish, value, index);
  64. }
  65. else {
  66. this.buffer.push(value);
  67. }
  68. };
  69. MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
  70. var innerSubscriber = new InnerSubscriber_1.InnerSubscriber(this, undefined, undefined);
  71. var destination = this.destination;
  72. destination.add(innerSubscriber);
  73. subscribeToResult_1.subscribeToResult(this, ish, value, index, innerSubscriber);
  74. };
  75. MergeScanSubscriber.prototype._complete = function () {
  76. this.hasCompleted = true;
  77. if (this.active === 0 && this.buffer.length === 0) {
  78. if (this.hasValue === false) {
  79. this.destination.next(this.acc);
  80. }
  81. this.destination.complete();
  82. }
  83. this.unsubscribe();
  84. };
  85. MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  86. var destination = this.destination;
  87. this.acc = innerValue;
  88. this.hasValue = true;
  89. destination.next(innerValue);
  90. };
  91. MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
  92. var buffer = this.buffer;
  93. var destination = this.destination;
  94. destination.remove(innerSub);
  95. this.active--;
  96. if (buffer.length > 0) {
  97. this._next(buffer.shift());
  98. }
  99. else if (this.active === 0 && this.hasCompleted) {
  100. if (this.hasValue === false) {
  101. this.destination.next(this.acc);
  102. }
  103. this.destination.complete();
  104. }
  105. };
  106. return MergeScanSubscriber;
  107. }(OuterSubscriber_1.OuterSubscriber));
  108. exports.MergeScanSubscriber = MergeScanSubscriber;
  109. //# sourceMappingURL=mergeScan.js.map