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