1 /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
4 export function mergeScan(accumulator, seed, concurrent) {
5 if (concurrent === void 0) {
6 concurrent = Number.POSITIVE_INFINITY;
8 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
10 var MergeScanOperator = /*@__PURE__*/ (function () {
11 function MergeScanOperator(accumulator, seed, concurrent) {
12 this.accumulator = accumulator;
14 this.concurrent = concurrent;
16 MergeScanOperator.prototype.call = function (subscriber, source) {
17 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
19 return MergeScanOperator;
21 export { MergeScanOperator };
22 var MergeScanSubscriber = /*@__PURE__*/ (function (_super) {
23 tslib_1.__extends(MergeScanSubscriber, _super);
24 function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
25 var _this = _super.call(this, destination) || this;
26 _this.accumulator = accumulator;
28 _this.concurrent = concurrent;
29 _this.hasValue = false;
30 _this.hasCompleted = false;
36 MergeScanSubscriber.prototype._next = function (value) {
37 if (this.active < this.concurrent) {
38 var index = this.index++;
39 var destination = this.destination;
42 var accumulator = this.accumulator;
43 ish = accumulator(this.acc, value, index);
46 return destination.error(e);
52 this.buffer.push(value);
55 MergeScanSubscriber.prototype._innerSub = function (ish) {
56 var innerSubscriber = new SimpleInnerSubscriber(this);
57 var destination = this.destination;
58 destination.add(innerSubscriber);
59 var innerSubscription = innerSubscribe(ish, innerSubscriber);
60 if (innerSubscription !== innerSubscriber) {
61 destination.add(innerSubscription);
64 MergeScanSubscriber.prototype._complete = function () {
65 this.hasCompleted = true;
66 if (this.active === 0 && this.buffer.length === 0) {
67 if (this.hasValue === false) {
68 this.destination.next(this.acc);
70 this.destination.complete();
74 MergeScanSubscriber.prototype.notifyNext = function (innerValue) {
75 var destination = this.destination;
76 this.acc = innerValue;
78 destination.next(innerValue);
80 MergeScanSubscriber.prototype.notifyComplete = function () {
81 var buffer = this.buffer;
83 if (buffer.length > 0) {
84 this._next(buffer.shift());
86 else if (this.active === 0 && this.hasCompleted) {
87 if (this.hasValue === false) {
88 this.destination.next(this.acc);
90 this.destination.complete();
93 return MergeScanSubscriber;
94 }(SimpleOuterSubscriber));
95 export { MergeScanSubscriber };
96 //# sourceMappingURL=mergeScan.js.map