repeatWhen.js
4.39 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 Subject_1 = require('../Subject');
var tryCatch_1 = require('../util/tryCatch');
var errorObject_1 = require('../util/errorObject');
var OuterSubscriber_1 = require('../OuterSubscriber');
var subscribeToResult_1 = require('../util/subscribeToResult');
/**
* Returns an Observable that emits the same values as the source observable with the exception of a `complete`.
* A `complete` will cause the emission of the Throwable that cause the complete to the Observable returned from
* notificationHandler. If that Observable calls onComplete or `complete` then retry will call `complete` or `error`
* on the child subscription. Otherwise, this Observable will resubscribe to the source observable, on a particular
* Scheduler.
*
* <img src="./img/repeatWhen.png" width="100%">
*
* @param {notificationHandler} receives an Observable of notifications with which a user can `complete` or `error`,
* aborting the retry.
* @param {scheduler} the Scheduler on which to subscribe to the source Observable.
* @return {Observable} the source Observable modified with retry logic.
* @method repeatWhen
* @owner Observable
*/
function repeatWhen(notifier) {
return this.lift(new RepeatWhenOperator(notifier, this));
}
exports.repeatWhen = repeatWhen;
var RepeatWhenOperator = (function () {
function RepeatWhenOperator(notifier, source) {
this.notifier = notifier;
this.source = source;
}
RepeatWhenOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, this.source));
};
return RepeatWhenOperator;
}());
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
var RepeatWhenSubscriber = (function (_super) {
__extends(RepeatWhenSubscriber, _super);
function RepeatWhenSubscriber(destination, notifier, source) {
_super.call(this, destination);
this.notifier = notifier;
this.source = source;
}
RepeatWhenSubscriber.prototype.complete = function () {
if (!this.isStopped) {
var notifications = this.notifications;
var retries = this.retries;
var retriesSubscription = this.retriesSubscription;
if (!retries) {
notifications = new Subject_1.Subject();
retries = tryCatch_1.tryCatch(this.notifier)(notifications);
if (retries === errorObject_1.errorObject) {
return _super.prototype.complete.call(this);
}
retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries);
}
else {
this.notifications = null;
this.retriesSubscription = null;
}
this.unsubscribe();
this.closed = false;
this.notifications = notifications;
this.retries = retries;
this.retriesSubscription = retriesSubscription;
notifications.next();
}
};
RepeatWhenSubscriber.prototype._unsubscribe = function () {
var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
if (notifications) {
notifications.unsubscribe();
this.notifications = null;
}
if (retriesSubscription) {
retriesSubscription.unsubscribe();
this.retriesSubscription = null;
}
this.retries = null;
};
RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
var _a = this, notifications = _a.notifications, retries = _a.retries, retriesSubscription = _a.retriesSubscription;
this.notifications = null;
this.retries = null;
this.retriesSubscription = null;
this.unsubscribe();
this.isStopped = false;
this.closed = false;
this.notifications = notifications;
this.retries = retries;
this.retriesSubscription = retriesSubscription;
this.source.subscribe(this);
};
return RepeatWhenSubscriber;
}(OuterSubscriber_1.OuterSubscriber));
//# sourceMappingURL=repeatWhen.js.map