523eb4a1a575885977b51f3f1695315af6f34fb4
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / mergeScan.js
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, value, index);
71         var destination = this.destination;
72         destination.add(innerSubscriber);
73         var innerSubscription = subscribeToResult_1.subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
74         if (innerSubscription !== innerSubscriber) {
75             destination.add(innerSubscription);
76         }
77     };
78     MergeScanSubscriber.prototype._complete = function () {
79         this.hasCompleted = true;
80         if (this.active === 0 && this.buffer.length === 0) {
81             if (this.hasValue === false) {
82                 this.destination.next(this.acc);
83             }
84             this.destination.complete();
85         }
86         this.unsubscribe();
87     };
88     MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
89         var destination = this.destination;
90         this.acc = innerValue;
91         this.hasValue = true;
92         destination.next(innerValue);
93     };
94     MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
95         var buffer = this.buffer;
96         var destination = this.destination;
97         destination.remove(innerSub);
98         this.active--;
99         if (buffer.length > 0) {
100             this._next(buffer.shift());
101         }
102         else if (this.active === 0 && this.hasCompleted) {
103             if (this.hasValue === false) {
104                 this.destination.next(this.acc);
105             }
106             this.destination.complete();
107         }
108     };
109     return MergeScanSubscriber;
110 }(OuterSubscriber_1.OuterSubscriber));
111 exports.MergeScanSubscriber = MergeScanSubscriber;
112 //# sourceMappingURL=mergeScan.js.map