1 | /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */
|
---|
2 | import * as tslib_1 from "tslib";
|
---|
3 | import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
|
---|
4 | export function expand(project, concurrent, scheduler) {
|
---|
5 | if (concurrent === void 0) {
|
---|
6 | concurrent = Number.POSITIVE_INFINITY;
|
---|
7 | }
|
---|
8 | concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
|
---|
9 | return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
|
---|
10 | }
|
---|
11 | var ExpandOperator = /*@__PURE__*/ (function () {
|
---|
12 | function ExpandOperator(project, concurrent, scheduler) {
|
---|
13 | this.project = project;
|
---|
14 | this.concurrent = concurrent;
|
---|
15 | this.scheduler = scheduler;
|
---|
16 | }
|
---|
17 | ExpandOperator.prototype.call = function (subscriber, source) {
|
---|
18 | return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
|
---|
19 | };
|
---|
20 | return ExpandOperator;
|
---|
21 | }());
|
---|
22 | export { ExpandOperator };
|
---|
23 | var ExpandSubscriber = /*@__PURE__*/ (function (_super) {
|
---|
24 | tslib_1.__extends(ExpandSubscriber, _super);
|
---|
25 | function ExpandSubscriber(destination, project, concurrent, scheduler) {
|
---|
26 | var _this = _super.call(this, destination) || this;
|
---|
27 | _this.project = project;
|
---|
28 | _this.concurrent = concurrent;
|
---|
29 | _this.scheduler = scheduler;
|
---|
30 | _this.index = 0;
|
---|
31 | _this.active = 0;
|
---|
32 | _this.hasCompleted = false;
|
---|
33 | if (concurrent < Number.POSITIVE_INFINITY) {
|
---|
34 | _this.buffer = [];
|
---|
35 | }
|
---|
36 | return _this;
|
---|
37 | }
|
---|
38 | ExpandSubscriber.dispatch = function (arg) {
|
---|
39 | var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
|
---|
40 | subscriber.subscribeToProjection(result, value, index);
|
---|
41 | };
|
---|
42 | ExpandSubscriber.prototype._next = function (value) {
|
---|
43 | var destination = this.destination;
|
---|
44 | if (destination.closed) {
|
---|
45 | this._complete();
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | var index = this.index++;
|
---|
49 | if (this.active < this.concurrent) {
|
---|
50 | destination.next(value);
|
---|
51 | try {
|
---|
52 | var project = this.project;
|
---|
53 | var result = project(value, index);
|
---|
54 | if (!this.scheduler) {
|
---|
55 | this.subscribeToProjection(result, value, index);
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | var state = { subscriber: this, result: result, value: value, index: index };
|
---|
59 | var destination_1 = this.destination;
|
---|
60 | destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
|
---|
61 | }
|
---|
62 | }
|
---|
63 | catch (e) {
|
---|
64 | destination.error(e);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | else {
|
---|
68 | this.buffer.push(value);
|
---|
69 | }
|
---|
70 | };
|
---|
71 | ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
|
---|
72 | this.active++;
|
---|
73 | var destination = this.destination;
|
---|
74 | destination.add(innerSubscribe(result, new SimpleInnerSubscriber(this)));
|
---|
75 | };
|
---|
76 | ExpandSubscriber.prototype._complete = function () {
|
---|
77 | this.hasCompleted = true;
|
---|
78 | if (this.hasCompleted && this.active === 0) {
|
---|
79 | this.destination.complete();
|
---|
80 | }
|
---|
81 | this.unsubscribe();
|
---|
82 | };
|
---|
83 | ExpandSubscriber.prototype.notifyNext = function (innerValue) {
|
---|
84 | this._next(innerValue);
|
---|
85 | };
|
---|
86 | ExpandSubscriber.prototype.notifyComplete = function () {
|
---|
87 | var buffer = this.buffer;
|
---|
88 | this.active--;
|
---|
89 | if (buffer && buffer.length > 0) {
|
---|
90 | this._next(buffer.shift());
|
---|
91 | }
|
---|
92 | if (this.hasCompleted && this.active === 0) {
|
---|
93 | this.destination.complete();
|
---|
94 | }
|
---|
95 | };
|
---|
96 | return ExpandSubscriber;
|
---|
97 | }(SimpleOuterSubscriber));
|
---|
98 | export { ExpandSubscriber };
|
---|
99 | //# sourceMappingURL=expand.js.map
|
---|