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;
|
---|
7 | }
|
---|
8 | return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
|
---|
9 | }
|
---|
10 | var MergeScanOperator = /*@__PURE__*/ (function () {
|
---|
11 | function MergeScanOperator(accumulator, seed, concurrent) {
|
---|
12 | this.accumulator = accumulator;
|
---|
13 | this.seed = seed;
|
---|
14 | this.concurrent = concurrent;
|
---|
15 | }
|
---|
16 | MergeScanOperator.prototype.call = function (subscriber, source) {
|
---|
17 | return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
|
---|
18 | };
|
---|
19 | return MergeScanOperator;
|
---|
20 | }());
|
---|
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;
|
---|
27 | _this.acc = acc;
|
---|
28 | _this.concurrent = concurrent;
|
---|
29 | _this.hasValue = false;
|
---|
30 | _this.hasCompleted = false;
|
---|
31 | _this.buffer = [];
|
---|
32 | _this.active = 0;
|
---|
33 | _this.index = 0;
|
---|
34 | return _this;
|
---|
35 | }
|
---|
36 | MergeScanSubscriber.prototype._next = function (value) {
|
---|
37 | if (this.active < this.concurrent) {
|
---|
38 | var index = this.index++;
|
---|
39 | var destination = this.destination;
|
---|
40 | var ish = void 0;
|
---|
41 | try {
|
---|
42 | var accumulator = this.accumulator;
|
---|
43 | ish = accumulator(this.acc, value, index);
|
---|
44 | }
|
---|
45 | catch (e) {
|
---|
46 | return destination.error(e);
|
---|
47 | }
|
---|
48 | this.active++;
|
---|
49 | this._innerSub(ish);
|
---|
50 | }
|
---|
51 | else {
|
---|
52 | this.buffer.push(value);
|
---|
53 | }
|
---|
54 | };
|
---|
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);
|
---|
62 | }
|
---|
63 | };
|
---|
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);
|
---|
69 | }
|
---|
70 | this.destination.complete();
|
---|
71 | }
|
---|
72 | this.unsubscribe();
|
---|
73 | };
|
---|
74 | MergeScanSubscriber.prototype.notifyNext = function (innerValue) {
|
---|
75 | var destination = this.destination;
|
---|
76 | this.acc = innerValue;
|
---|
77 | this.hasValue = true;
|
---|
78 | destination.next(innerValue);
|
---|
79 | };
|
---|
80 | MergeScanSubscriber.prototype.notifyComplete = function () {
|
---|
81 | var buffer = this.buffer;
|
---|
82 | this.active--;
|
---|
83 | if (buffer.length > 0) {
|
---|
84 | this._next(buffer.shift());
|
---|
85 | }
|
---|
86 | else if (this.active === 0 && this.hasCompleted) {
|
---|
87 | if (this.hasValue === false) {
|
---|
88 | this.destination.next(this.acc);
|
---|
89 | }
|
---|
90 | this.destination.complete();
|
---|
91 | }
|
---|
92 | };
|
---|
93 | return MergeScanSubscriber;
|
---|
94 | }(SimpleOuterSubscriber));
|
---|
95 | export { MergeScanSubscriber };
|
---|
96 | //# sourceMappingURL=mergeScan.js.map
|
---|