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;
10 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
12 var MergeScanOperator = /*@__PURE__*/ (function () {
13 function MergeScanOperator(accumulator, seed, concurrent) {
14 this.accumulator = accumulator;
16 this.concurrent = concurrent;
18 MergeScanOperator.prototype.call = function (subscriber, source) {
19 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
21 return MergeScanOperator;
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;
30 _this.concurrent = concurrent;
31 _this.hasValue = false;
32 _this.hasCompleted = false;
38 MergeScanSubscriber.prototype._next = function (value) {
39 if (this.active < this.concurrent) {
40 var index = this.index++;
41 var destination = this.destination;
44 var accumulator = this.accumulator;
45 ish = accumulator(this.acc, value, index);
48 return destination.error(e);
51 this._innerSub(ish, value, index);
54 this.buffer.push(value);
57 MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
58 var innerSubscriber = new InnerSubscriber(this, value, index);
59 var destination = this.destination;
60 destination.add(innerSubscriber);
61 var innerSubscription = subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
62 if (innerSubscription !== innerSubscriber) {
63 destination.add(innerSubscription);
66 MergeScanSubscriber.prototype._complete = function () {
67 this.hasCompleted = true;
68 if (this.active === 0 && this.buffer.length === 0) {
69 if (this.hasValue === false) {
70 this.destination.next(this.acc);
72 this.destination.complete();
76 MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
77 var destination = this.destination;
78 this.acc = innerValue;
80 destination.next(innerValue);
82 MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
83 var buffer = this.buffer;
84 var destination = this.destination;
85 destination.remove(innerSub);
87 if (buffer.length > 0) {
88 this._next(buffer.shift());
90 else if (this.active === 0 && this.hasCompleted) {
91 if (this.hasValue === false) {
92 this.destination.next(this.acc);
94 this.destination.complete();
97 return MergeScanSubscriber;
99 export { MergeScanSubscriber };
100 //# sourceMappingURL=mergeScan.js.map