summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/retry/lib
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/retry/lib')
-rw-r--r--deps/npm/node_modules/retry/lib/retry.js9
-rw-r--r--deps/npm/node_modules/retry/lib/retry_operation.js17
2 files changed, 21 insertions, 5 deletions
diff --git a/deps/npm/node_modules/retry/lib/retry.js b/deps/npm/node_modules/retry/lib/retry.js
index 77428cfd00..dcb5768072 100644
--- a/deps/npm/node_modules/retry/lib/retry.js
+++ b/deps/npm/node_modules/retry/lib/retry.js
@@ -4,7 +4,8 @@ exports.operation = function(options) {
var timeouts = exports.timeouts(options);
return new RetryOperation(timeouts, {
forever: options && options.forever,
- unref: options && options.unref
+ unref: options && options.unref,
+ maxRetryTime: options && options.maxRetryTime
});
};
@@ -75,9 +76,9 @@ exports.wrap = function(obj, options, methods) {
var method = methods[i];
var original = obj[method];
- obj[method] = function retryWrapper() {
+ obj[method] = function retryWrapper(original) {
var op = exports.operation(options);
- var args = Array.prototype.slice.call(arguments);
+ var args = Array.prototype.slice.call(arguments, 1);
var callback = args.pop();
args.push(function(err) {
@@ -93,7 +94,7 @@ exports.wrap = function(obj, options, methods) {
op.attempt(function() {
original.apply(obj, args);
});
- };
+ }.bind(obj, original);
obj[method].options = options;
}
};
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);
};