mergeScan.js
3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var tryCatch_1 = require('../util/tryCatch');
var errorObject_1 = require('../util/errorObject');
var subscribeToResult_1 = require('../util/subscribeToResult');
var OuterSubscriber_1 = require('../OuterSubscriber');
/**
* @param project
* @param seed
* @param concurrent
* @return {Observable<R>|WebSocketSubject<T>|Observable<T>}
* @method mergeScan
* @owner Observable
*/
function mergeScan(project, seed, concurrent) {
if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
return this.lift(new MergeScanOperator(project, seed, concurrent));
}
exports.mergeScan = mergeScan;
var MergeScanOperator = (function () {
function MergeScanOperator(project, seed, concurrent) {
this.project = project;
this.seed = seed;
this.concurrent = concurrent;
}
MergeScanOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new MergeScanSubscriber(subscriber, this.project, this.seed, this.concurrent));
};
return MergeScanOperator;
}());
exports.MergeScanOperator = MergeScanOperator;
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
var MergeScanSubscriber = (function (_super) {
__extends(MergeScanSubscriber, _super);
function MergeScanSubscriber(destination, project, acc, concurrent) {
_super.call(this, destination);
this.project = project;
this.acc = acc;
this.concurrent = concurrent;
this.hasValue = false;
this.hasCompleted = false;
this.buffer = [];
this.active = 0;
this.index = 0;
}
MergeScanSubscriber.prototype._next = function (value) {
if (this.active < this.concurrent) {
var index = this.index++;
var ish = tryCatch_1.tryCatch(this.project)(this.acc, value);
var destination = this.destination;
if (ish === errorObject_1.errorObject) {
destination.error(errorObject_1.errorObject.e);
}
else {
this.active++;
this._innerSub(ish, value, index);
}
}
else {
this.buffer.push(value);
}
};
MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
this.add(subscribeToResult_1.subscribeToResult(this, ish, value, index));
};
MergeScanSubscriber.prototype._complete = function () {
this.hasCompleted = true;
if (this.active === 0 && this.buffer.length === 0) {
if (this.hasValue === false) {
this.destination.next(this.acc);
}
this.destination.complete();
}
};
MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
var destination = this.destination;
this.acc = innerValue;
this.hasValue = true;
destination.next(innerValue);
};
MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
var buffer = this.buffer;
this.remove(innerSub);
this.active--;
if (buffer.length > 0) {
this._next(buffer.shift());
}
else if (this.active === 0 && this.hasCompleted) {
if (this.hasValue === false) {
this.destination.next(this.acc);
}
this.destination.complete();
}
};
return MergeScanSubscriber;
}(OuterSubscriber_1.OuterSubscriber));
exports.MergeScanSubscriber = MergeScanSubscriber;
//# sourceMappingURL=mergeScan.js.map