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.

expand.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 tryCatch_1 = require("../util/tryCatch");
  17. var errorObject_1 = require("../util/errorObject");
  18. var OuterSubscriber_1 = require("../OuterSubscriber");
  19. var subscribeToResult_1 = require("../util/subscribeToResult");
  20. function expand(project, concurrent, scheduler) {
  21. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  22. if (scheduler === void 0) { scheduler = undefined; }
  23. concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
  24. return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
  25. }
  26. exports.expand = expand;
  27. var ExpandOperator = (function () {
  28. function ExpandOperator(project, concurrent, scheduler) {
  29. this.project = project;
  30. this.concurrent = concurrent;
  31. this.scheduler = scheduler;
  32. }
  33. ExpandOperator.prototype.call = function (subscriber, source) {
  34. return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
  35. };
  36. return ExpandOperator;
  37. }());
  38. exports.ExpandOperator = ExpandOperator;
  39. var ExpandSubscriber = (function (_super) {
  40. __extends(ExpandSubscriber, _super);
  41. function ExpandSubscriber(destination, project, concurrent, scheduler) {
  42. var _this = _super.call(this, destination) || this;
  43. _this.project = project;
  44. _this.concurrent = concurrent;
  45. _this.scheduler = scheduler;
  46. _this.index = 0;
  47. _this.active = 0;
  48. _this.hasCompleted = false;
  49. if (concurrent < Number.POSITIVE_INFINITY) {
  50. _this.buffer = [];
  51. }
  52. return _this;
  53. }
  54. ExpandSubscriber.dispatch = function (arg) {
  55. var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
  56. subscriber.subscribeToProjection(result, value, index);
  57. };
  58. ExpandSubscriber.prototype._next = function (value) {
  59. var destination = this.destination;
  60. if (destination.closed) {
  61. this._complete();
  62. return;
  63. }
  64. var index = this.index++;
  65. if (this.active < this.concurrent) {
  66. destination.next(value);
  67. var result = tryCatch_1.tryCatch(this.project)(value, index);
  68. if (result === errorObject_1.errorObject) {
  69. destination.error(errorObject_1.errorObject.e);
  70. }
  71. else if (!this.scheduler) {
  72. this.subscribeToProjection(result, value, index);
  73. }
  74. else {
  75. var state = { subscriber: this, result: result, value: value, index: index };
  76. var destination_1 = this.destination;
  77. destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
  78. }
  79. }
  80. else {
  81. this.buffer.push(value);
  82. }
  83. };
  84. ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
  85. this.active++;
  86. var destination = this.destination;
  87. destination.add(subscribeToResult_1.subscribeToResult(this, result, value, index));
  88. };
  89. ExpandSubscriber.prototype._complete = function () {
  90. this.hasCompleted = true;
  91. if (this.hasCompleted && this.active === 0) {
  92. this.destination.complete();
  93. }
  94. this.unsubscribe();
  95. };
  96. ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  97. this._next(innerValue);
  98. };
  99. ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
  100. var buffer = this.buffer;
  101. var destination = this.destination;
  102. destination.remove(innerSub);
  103. this.active--;
  104. if (buffer && buffer.length > 0) {
  105. this._next(buffer.shift());
  106. }
  107. if (this.hasCompleted && this.active === 0) {
  108. this.destination.complete();
  109. }
  110. };
  111. return ExpandSubscriber;
  112. }(OuterSubscriber_1.OuterSubscriber));
  113. exports.ExpandSubscriber = ExpandSubscriber;
  114. //# sourceMappingURL=expand.js.map