43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
|
|
import * as tslib_1 from "tslib";
|
|
import { Subscriber } from '../Subscriber';
|
|
export function retry(count) {
|
|
if (count === void 0) {
|
|
count = -1;
|
|
}
|
|
return function (source) { return source.lift(new RetryOperator(count, source)); };
|
|
}
|
|
var RetryOperator = /*@__PURE__*/ (function () {
|
|
function RetryOperator(count, source) {
|
|
this.count = count;
|
|
this.source = source;
|
|
}
|
|
RetryOperator.prototype.call = function (subscriber, source) {
|
|
return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
|
|
};
|
|
return RetryOperator;
|
|
}());
|
|
var RetrySubscriber = /*@__PURE__*/ (function (_super) {
|
|
tslib_1.__extends(RetrySubscriber, _super);
|
|
function RetrySubscriber(destination, count, source) {
|
|
var _this = _super.call(this, destination) || this;
|
|
_this.count = count;
|
|
_this.source = source;
|
|
return _this;
|
|
}
|
|
RetrySubscriber.prototype.error = function (err) {
|
|
if (!this.isStopped) {
|
|
var _a = this, source = _a.source, count = _a.count;
|
|
if (count === 0) {
|
|
return _super.prototype.error.call(this, err);
|
|
}
|
|
else if (count > -1) {
|
|
this.count = count - 1;
|
|
}
|
|
source.subscribe(this._unsubscribeAndRecycle());
|
|
}
|
|
};
|
|
return RetrySubscriber;
|
|
}(Subscriber));
|
|
//# sourceMappingURL=retry.js.map
|