1 /** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { OuterSubscriber } from '../OuterSubscriber';
4 import { subscribeToResult } from '../util/subscribeToResult';
5 export function expand(project, concurrent, scheduler) {
6 if (concurrent === void 0) {
7 concurrent = Number.POSITIVE_INFINITY;
9 if (scheduler === void 0) {
10 scheduler = undefined;
12 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
13 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
15 var ExpandOperator = /*@__PURE__*/ (function () {
16 function ExpandOperator(project, concurrent, scheduler) {
17 this.project = project;
18 this.concurrent = concurrent;
19 this.scheduler = scheduler;
21 ExpandOperator.prototype.call = function (subscriber, source) {
22 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
24 return ExpandOperator;
26 export { ExpandOperator };
27 var ExpandSubscriber = /*@__PURE__*/ (function (_super) {
28 tslib_1.__extends(ExpandSubscriber, _super);
29 function ExpandSubscriber(destination, project, concurrent, scheduler) {
30 var _this = _super.call(this, destination) || this;
31 _this.project = project;
32 _this.concurrent = concurrent;
33 _this.scheduler = scheduler;
36 _this.hasCompleted = false;
37 if (concurrent < Number.POSITIVE_INFINITY) {
42 ExpandSubscriber.dispatch = function (arg) {
43 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
44 subscriber.subscribeToProjection(result, value, index);
46 ExpandSubscriber.prototype._next = function (value) {
47 var destination = this.destination;
48 if (destination.closed) {
52 var index = this.index++;
53 if (this.active < this.concurrent) {
54 destination.next(value);
56 var project = this.project;
57 var result = project(value, index);
58 if (!this.scheduler) {
59 this.subscribeToProjection(result, value, index);
62 var state = { subscriber: this, result: result, value: value, index: index };
63 var destination_1 = this.destination;
64 destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
72 this.buffer.push(value);
75 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
77 var destination = this.destination;
78 destination.add(subscribeToResult(this, result, value, index));
80 ExpandSubscriber.prototype._complete = function () {
81 this.hasCompleted = true;
82 if (this.hasCompleted && this.active === 0) {
83 this.destination.complete();
87 ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
88 this._next(innerValue);
90 ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
91 var buffer = this.buffer;
92 var destination = this.destination;
93 destination.remove(innerSub);
95 if (buffer && buffer.length > 0) {
96 this._next(buffer.shift());
98 if (this.hasCompleted && this.active === 0) {
99 this.destination.complete();
102 return ExpandSubscriber;
104 export { ExpandSubscriber };
105 //# sourceMappingURL=expand.js.map