summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/node_modules/retry/lib')
-rw-r--r--deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry.js99
-rw-r--r--deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry_operation.js143
2 files changed, 0 insertions, 242 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry.js b/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry.js
deleted file mode 100644
index 77428cfd00..0000000000
--- a/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry.js
+++ /dev/null
@@ -1,99 +0,0 @@
-var RetryOperation = require('./retry_operation');
-
-exports.operation = function(options) {
- var timeouts = exports.timeouts(options);
- return new RetryOperation(timeouts, {
- forever: options && options.forever,
- unref: options && options.unref
- });
-};
-
-exports.timeouts = function(options) {
- if (options instanceof Array) {
- return [].concat(options);
- }
-
- var opts = {
- retries: 10,
- factor: 2,
- minTimeout: 1 * 1000,
- maxTimeout: Infinity,
- randomize: false
- };
- for (var key in options) {
- opts[key] = options[key];
- }
-
- if (opts.minTimeout > opts.maxTimeout) {
- throw new Error('minTimeout is greater than maxTimeout');
- }
-
- var timeouts = [];
- for (var i = 0; i < opts.retries; i++) {
- timeouts.push(this.createTimeout(i, opts));
- }
-
- if (options && options.forever && !timeouts.length) {
- timeouts.push(this.createTimeout(i, opts));
- }
-
- // sort the array numerically ascending
- timeouts.sort(function(a,b) {
- return a - b;
- });
-
- return timeouts;
-};
-
-exports.createTimeout = function(attempt, opts) {
- var random = (opts.randomize)
- ? (Math.random() + 1)
- : 1;
-
- var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
- timeout = Math.min(timeout, opts.maxTimeout);
-
- return timeout;
-};
-
-exports.wrap = function(obj, options, methods) {
- if (options instanceof Array) {
- methods = options;
- options = null;
- }
-
- if (!methods) {
- methods = [];
- for (var key in obj) {
- if (typeof obj[key] === 'function') {
- methods.push(key);
- }
- }
- }
-
- for (var i = 0; i < methods.length; i++) {
- var method = methods[i];
- var original = obj[method];
-
- obj[method] = function retryWrapper() {
- var op = exports.operation(options);
- var args = Array.prototype.slice.call(arguments);
- var callback = args.pop();
-
- args.push(function(err) {
- if (op.retry(err)) {
- return;
- }
- if (err) {
- arguments[0] = op.mainError();
- }
- callback.apply(this, arguments);
- });
-
- op.attempt(function() {
- original.apply(obj, args);
- });
- };
- obj[method].options = options;
- }
-};
diff --git a/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry_operation.js b/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry_operation.js
deleted file mode 100644
index 2b3db8e177..0000000000
--- a/deps/npm/node_modules/npm-registry-client/node_modules/retry/lib/retry_operation.js
+++ /dev/null
@@ -1,143 +0,0 @@
-function RetryOperation(timeouts, options) {
- // Compatibility for the old (timeouts, retryForever) signature
- if (typeof options === 'boolean') {
- options = { forever: options };
- }
-
- this._timeouts = timeouts;
- this._options = options || {};
- this._fn = null;
- this._errors = [];
- this._attempts = 1;
- this._operationTimeout = null;
- this._operationTimeoutCb = null;
- this._timeout = null;
-
- if (this._options.forever) {
- this._cachedTimeouts = this._timeouts.slice(0);
- }
-}
-module.exports = RetryOperation;
-
-RetryOperation.prototype.stop = function() {
- if (this._timeout) {
- clearTimeout(this._timeout);
- }
-
- this._timeouts = [];
- this._cachedTimeouts = null;
-};
-
-RetryOperation.prototype.retry = function(err) {
- if (this._timeout) {
- clearTimeout(this._timeout);
- }
-
- if (!err) {
- return false;
- }
-
- this._errors.push(err);
-
- var timeout = this._timeouts.shift();
- if (timeout === undefined) {
- if (this._cachedTimeouts) {
- // retry forever, only keep last error
- this._errors.splice(this._errors.length - 1, this._errors.length);
- this._timeouts = this._cachedTimeouts.slice(0);
- timeout = this._timeouts.shift();
- } else {
- return false;
- }
- }
-
- var self = this;
- var timer = setTimeout(function() {
- self._attempts++;
-
- if (self._operationTimeoutCb) {
- self._timeout = setTimeout(function() {
- self._operationTimeoutCb(self._attempts);
- }, self._operationTimeout);
-
- if (this._options.unref) {
- self._timeout.unref();
- }
- }
-
- self._fn(self._attempts);
- }, timeout);
-
- if (this._options.unref) {
- timer.unref();
- }
-
- return true;
-};
-
-RetryOperation.prototype.attempt = function(fn, timeoutOps) {
- this._fn = fn;
-
- if (timeoutOps) {
- if (timeoutOps.timeout) {
- this._operationTimeout = timeoutOps.timeout;
- }
- if (timeoutOps.cb) {
- this._operationTimeoutCb = timeoutOps.cb;
- }
- }
-
- var self = this;
- if (this._operationTimeoutCb) {
- this._timeout = setTimeout(function() {
- self._operationTimeoutCb();
- }, self._operationTimeout);
- }
-
- this._fn(this._attempts);
-};
-
-RetryOperation.prototype.try = function(fn) {
- console.log('Using RetryOperation.try() is deprecated');
- this.attempt(fn);
-};
-
-RetryOperation.prototype.start = function(fn) {
- console.log('Using RetryOperation.start() is deprecated');
- this.attempt(fn);
-};
-
-RetryOperation.prototype.start = RetryOperation.prototype.try;
-
-RetryOperation.prototype.errors = function() {
- return this._errors;
-};
-
-RetryOperation.prototype.attempts = function() {
- return this._attempts;
-};
-
-RetryOperation.prototype.mainError = function() {
- if (this._errors.length === 0) {
- return null;
- }
-
- var counts = {};
- var mainError = null;
- var mainErrorCount = 0;
-
- for (var i = 0; i < this._errors.length; i++) {
- var error = this._errors[i];
- var message = error.message;
- var count = (counts[message] || 0) + 1;
-
- counts[message] = count;
-
- if (count >= mainErrorCount) {
- mainError = error;
- mainErrorCount = count;
- }
- }
-
- return mainError;
-};