summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/retry/lib/retry_operation.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/retry/lib/retry_operation.js')
-rw-r--r--deps/npm/node_modules/retry/lib/retry_operation.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/deps/npm/node_modules/retry/lib/retry_operation.js b/deps/npm/node_modules/retry/lib/retry_operation.js
index 2b3db8e177..1e564696fe 100644
--- a/deps/npm/node_modules/retry/lib/retry_operation.js
+++ b/deps/npm/node_modules/retry/lib/retry_operation.js
@@ -4,14 +4,17 @@ function RetryOperation(timeouts, options) {
options = { forever: options };
}
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
this._timeouts = timeouts;
this._options = options || {};
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
this._fn = null;
this._errors = [];
this._attempts = 1;
this._operationTimeout = null;
this._operationTimeoutCb = null;
this._timeout = null;
+ this._operationStart = null;
if (this._options.forever) {
this._cachedTimeouts = this._timeouts.slice(0);
@@ -19,6 +22,11 @@ function RetryOperation(timeouts, options) {
}
module.exports = RetryOperation;
+RetryOperation.prototype.reset = function() {
+ this._attempts = 1;
+ this._timeouts = this._originalTimeouts;
+}
+
RetryOperation.prototype.stop = function() {
if (this._timeout) {
clearTimeout(this._timeout);
@@ -36,6 +44,11 @@ RetryOperation.prototype.retry = function(err) {
if (!err) {
return false;
}
+ var currentTime = new Date().getTime();
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
+ this._errors.unshift(new Error('RetryOperation timeout occurred'));
+ return false;
+ }
this._errors.push(err);
@@ -60,7 +73,7 @@ RetryOperation.prototype.retry = function(err) {
self._operationTimeoutCb(self._attempts);
}, self._operationTimeout);
- if (this._options.unref) {
+ if (self._options.unref) {
self._timeout.unref();
}
}
@@ -94,6 +107,8 @@ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
}, self._operationTimeout);
}
+ this._operationStart = new Date().getTime();
+
this._fn(this._attempts);
};