"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Observable = require("zen-observable");
var link_1 = require("./link");
var RetryLink = (function (_super) {
__extends(RetryLink, _super);
function RetryLink(params) {
var _this = _super.call(this) || this;
_this.count = 0;
_this.defaultInterval = function (delay) { return delay; };
_this.max = params && params.max || 10;
_this.delay = params && params.delay || 300;
_this.interval = params && params.interval || _this.defaultInterval;
return _this;
}
RetryLink.prototype.request = function (operation, forward) {
var _this = this;
return new Observable(function (observer) {
var subscriber = {
next: function (data) {
_this.count = 0;
observer.next(data);
},
error: function (error) {
_this.count++;
if (_this.count < _this.max) {
_this.timer = setTimeout(function () {
var observable = forward(operation);
_this.subscription = observable.subscribe(subscriber);
}, _this.interval(_this.delay, _this.count));
}
else {
observer.error(error);
}
},
complete: observer.complete.bind(observer),
};
_this.subscription = forward(operation).subscribe(subscriber);
return function () {
_this.subscription.unsubscribe();
if (_this.timer) {
clearTimeout(_this.timer);
}
};
});
};
return RetryLink;
}(link_1.ApolloLink));
exports.default = RetryLink;
//# sourceMappingURL=retryLink.js.map |