1 | /** PURE_IMPORTS_START tslib,_Subject,_innerSubscribe PURE_IMPORTS_END */
|
---|
2 | import * as tslib_1 from "tslib";
|
---|
3 | import { Subject } from '../Subject';
|
---|
4 | import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
|
---|
5 | export function retryWhen(notifier) {
|
---|
6 | return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
|
---|
7 | }
|
---|
8 | var RetryWhenOperator = /*@__PURE__*/ (function () {
|
---|
9 | function RetryWhenOperator(notifier, source) {
|
---|
10 | this.notifier = notifier;
|
---|
11 | this.source = source;
|
---|
12 | }
|
---|
13 | RetryWhenOperator.prototype.call = function (subscriber, source) {
|
---|
14 | return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
|
---|
15 | };
|
---|
16 | return RetryWhenOperator;
|
---|
17 | }());
|
---|
18 | var RetryWhenSubscriber = /*@__PURE__*/ (function (_super) {
|
---|
19 | tslib_1.__extends(RetryWhenSubscriber, _super);
|
---|
20 | function RetryWhenSubscriber(destination, notifier, source) {
|
---|
21 | var _this = _super.call(this, destination) || this;
|
---|
22 | _this.notifier = notifier;
|
---|
23 | _this.source = source;
|
---|
24 | return _this;
|
---|
25 | }
|
---|
26 | RetryWhenSubscriber.prototype.error = function (err) {
|
---|
27 | if (!this.isStopped) {
|
---|
28 | var errors = this.errors;
|
---|
29 | var retries = this.retries;
|
---|
30 | var retriesSubscription = this.retriesSubscription;
|
---|
31 | if (!retries) {
|
---|
32 | errors = new Subject();
|
---|
33 | try {
|
---|
34 | var notifier = this.notifier;
|
---|
35 | retries = notifier(errors);
|
---|
36 | }
|
---|
37 | catch (e) {
|
---|
38 | return _super.prototype.error.call(this, e);
|
---|
39 | }
|
---|
40 | retriesSubscription = innerSubscribe(retries, new SimpleInnerSubscriber(this));
|
---|
41 | }
|
---|
42 | else {
|
---|
43 | this.errors = undefined;
|
---|
44 | this.retriesSubscription = undefined;
|
---|
45 | }
|
---|
46 | this._unsubscribeAndRecycle();
|
---|
47 | this.errors = errors;
|
---|
48 | this.retries = retries;
|
---|
49 | this.retriesSubscription = retriesSubscription;
|
---|
50 | errors.next(err);
|
---|
51 | }
|
---|
52 | };
|
---|
53 | RetryWhenSubscriber.prototype._unsubscribe = function () {
|
---|
54 | var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
|
---|
55 | if (errors) {
|
---|
56 | errors.unsubscribe();
|
---|
57 | this.errors = undefined;
|
---|
58 | }
|
---|
59 | if (retriesSubscription) {
|
---|
60 | retriesSubscription.unsubscribe();
|
---|
61 | this.retriesSubscription = undefined;
|
---|
62 | }
|
---|
63 | this.retries = undefined;
|
---|
64 | };
|
---|
65 | RetryWhenSubscriber.prototype.notifyNext = function () {
|
---|
66 | var _unsubscribe = this._unsubscribe;
|
---|
67 | this._unsubscribe = null;
|
---|
68 | this._unsubscribeAndRecycle();
|
---|
69 | this._unsubscribe = _unsubscribe;
|
---|
70 | this.source.subscribe(this);
|
---|
71 | };
|
---|
72 | return RetryWhenSubscriber;
|
---|
73 | }(SimpleOuterSubscriber));
|
---|
74 | //# sourceMappingURL=retryWhen.js.map
|
---|