Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm5 / internal / operators / mergeMap.js
1 /** PURE_IMPORTS_START tslib,_util_subscribeToResult,_OuterSubscriber,_InnerSubscriber,_map,_observable_from 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 import { map } from './map';
7 import { from } from '../observable/from';
8 export function mergeMap(project, resultSelector, concurrent) {
9     if (concurrent === void 0) {
10         concurrent = Number.POSITIVE_INFINITY;
11     }
12     if (typeof resultSelector === 'function') {
13         return function (source) { return source.pipe(mergeMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }, concurrent)); };
14     }
15     else if (typeof resultSelector === 'number') {
16         concurrent = resultSelector;
17     }
18     return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };
19 }
20 var MergeMapOperator = /*@__PURE__*/ (function () {
21     function MergeMapOperator(project, concurrent) {
22         if (concurrent === void 0) {
23             concurrent = Number.POSITIVE_INFINITY;
24         }
25         this.project = project;
26         this.concurrent = concurrent;
27     }
28     MergeMapOperator.prototype.call = function (observer, source) {
29         return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));
30     };
31     return MergeMapOperator;
32 }());
33 export { MergeMapOperator };
34 var MergeMapSubscriber = /*@__PURE__*/ (function (_super) {
35     tslib_1.__extends(MergeMapSubscriber, _super);
36     function MergeMapSubscriber(destination, project, concurrent) {
37         if (concurrent === void 0) {
38             concurrent = Number.POSITIVE_INFINITY;
39         }
40         var _this = _super.call(this, destination) || this;
41         _this.project = project;
42         _this.concurrent = concurrent;
43         _this.hasCompleted = false;
44         _this.buffer = [];
45         _this.active = 0;
46         _this.index = 0;
47         return _this;
48     }
49     MergeMapSubscriber.prototype._next = function (value) {
50         if (this.active < this.concurrent) {
51             this._tryNext(value);
52         }
53         else {
54             this.buffer.push(value);
55         }
56     };
57     MergeMapSubscriber.prototype._tryNext = function (value) {
58         var result;
59         var index = this.index++;
60         try {
61             result = this.project(value, index);
62         }
63         catch (err) {
64             this.destination.error(err);
65             return;
66         }
67         this.active++;
68         this._innerSub(result, value, index);
69     };
70     MergeMapSubscriber.prototype._innerSub = function (ish, value, index) {
71         var innerSubscriber = new InnerSubscriber(this, value, index);
72         var destination = this.destination;
73         destination.add(innerSubscriber);
74         var innerSubscription = subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
75         if (innerSubscription !== innerSubscriber) {
76             destination.add(innerSubscription);
77         }
78     };
79     MergeMapSubscriber.prototype._complete = function () {
80         this.hasCompleted = true;
81         if (this.active === 0 && this.buffer.length === 0) {
82             this.destination.complete();
83         }
84         this.unsubscribe();
85     };
86     MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
87         this.destination.next(innerValue);
88     };
89     MergeMapSubscriber.prototype.notifyComplete = function (innerSub) {
90         var buffer = this.buffer;
91         this.remove(innerSub);
92         this.active--;
93         if (buffer.length > 0) {
94             this._next(buffer.shift());
95         }
96         else if (this.active === 0 && this.hasCompleted) {
97             this.destination.complete();
98         }
99     };
100     return MergeMapSubscriber;
101 }(OuterSubscriber));
102 export { MergeMapSubscriber };
103 export var flatMap = mergeMap;
104 //# sourceMappingURL=mergeMap.js.map