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