Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-09-10 00:58:52 +0300
committerRebecca Turner <me@re-becca.org>2015-09-10 23:47:22 +0300
commit349c4df356c81aa3db6683f7ad937af641693d14 (patch)
treebca1da697e3b2ee50047644c351fa3344157d99b /node_modules/retry
parentf5075513864fd50ee3f521f8306235c0dd8c2492 (diff)
retry@0.7.0
Diffstat (limited to 'node_modules/retry')
-rw-r--r--node_modules/retry/.npmignore1
-rw-r--r--node_modules/retry/Makefile15
-rw-r--r--node_modules/retry/Readme.md13
-rw-r--r--node_modules/retry/example/dns.js4
-rw-r--r--node_modules/retry/lib/retry.js10
-rw-r--r--node_modules/retry/lib/retry_operation.js27
-rw-r--r--node_modules/retry/package.json34
-rw-r--r--node_modules/retry/test/integration/test-retry-operation.js28
8 files changed, 101 insertions, 31 deletions
diff --git a/node_modules/retry/.npmignore b/node_modules/retry/.npmignore
index 5a23aa6a0..e7726a071 100644
--- a/node_modules/retry/.npmignore
+++ b/node_modules/retry/.npmignore
@@ -1 +1,2 @@
/node_modules/*
+npm-debug.log
diff --git a/node_modules/retry/Makefile b/node_modules/retry/Makefile
index a6e68c418..eee21a99d 100644
--- a/node_modules/retry/Makefile
+++ b/node_modules/retry/Makefile
@@ -3,5 +3,20 @@ SHELL := /bin/bash
test:
@node test/runner.js
+release-major: test
+ npm version major -m "Release %s"
+ git push
+ npm publish
+
+release-minor: test
+ npm version minor -m "Release %s"
+ git push
+ npm publish
+
+release-patch: test
+ npm version patch -m "Release %s"
+ git push
+ npm publish
+
.PHONY: test
diff --git a/node_modules/retry/Readme.md b/node_modules/retry/Readme.md
index ba6602205..f044025c0 100644
--- a/node_modules/retry/Readme.md
+++ b/node_modules/retry/Readme.md
@@ -96,10 +96,21 @@ Explaining the various values from left to right:
To make this a little easier for you, use wolfram alpha to do the calculations:
-[http://www.wolframalpha.com/input/?i=Sum%5B1000*x^k%2C+{k%2C+0%2C+9}%5D+%3D+5+*+60+*+1000]()
+<http://www.wolframalpha.com/input/?i=Sum%5B1000*x^k%2C+{k%2C+0%2C+9}%5D+%3D+5+*+60+*+1000>
[article]: http://dthain.blogspot.com/2009/02/exponential-backoff-in-distributed.html
+### retry.createTimeout(attempt, opts)
+
+Returns a new `timeout` (integer in milliseconds) based on the given parameters.
+
+`attempt` is an integer representing for which retry the timeout should be calculated. If your retry operation was executed 4 times you had one attempt and 3 retries. If you then want to calculate a new timeout, you should set `attempt` to 4 (attempts are zero-indexed).
+
+`opts` can include `factor`, `minTimeout`, `randomize` (boolean) and `maxTimeout`. They are documented above.
+
+`retry.createTimeout()` is used internally by `retry.timeouts()` and is public for you to be able to create your own timeouts for reinserting an item, see [issue #13](https://github.com/tim-kos/node-retry/issues/13).
+
+
### new RetryOperation(timeouts)
Creates a new `RetryOperation` where `timeouts` is an array where each value is
diff --git a/node_modules/retry/example/dns.js b/node_modules/retry/example/dns.js
index e4082af72..d6351e9d0 100644
--- a/node_modules/retry/example/dns.js
+++ b/node_modules/retry/example/dns.js
@@ -3,7 +3,7 @@ var retry = require('../lib/retry');
function faultTolerantResolve(address, cb) {
var opts = {
- times: 2,
+ retries: 2,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: 2 * 1000,
@@ -28,4 +28,4 @@ faultTolerantResolve('nodejs.org', function(err, errors, addresses) {
console.warn('addresses:');
console.log(addresses);
-}); \ No newline at end of file
+});
diff --git a/node_modules/retry/lib/retry.js b/node_modules/retry/lib/retry.js
index 38406860d..646670022 100644
--- a/node_modules/retry/lib/retry.js
+++ b/node_modules/retry/lib/retry.js
@@ -1,8 +1,10 @@
var RetryOperation = require('./retry_operation');
exports.operation = function(options) {
+ var retryForever = false;
+ if (options && options.forever === true) retryForever = true;
var timeouts = exports.timeouts(options);
- return new RetryOperation(timeouts);
+ return new RetryOperation(timeouts, retryForever);
};
exports.timeouts = function(options) {
@@ -27,7 +29,7 @@ exports.timeouts = function(options) {
var timeouts = [];
for (var i = 0; i < opts.retries; i++) {
- timeouts.push(this._createTimeout(i, opts));
+ timeouts.push(this.createTimeout(i, opts));
}
// sort the array numerically ascending
@@ -38,7 +40,7 @@ exports.timeouts = function(options) {
return timeouts;
};
-exports._createTimeout = function(attempt, opts) {
+exports.createTimeout = function(attempt, opts) {
var random = (opts.randomize)
? (Math.random() + 1)
: 1;
@@ -47,4 +49,4 @@ exports._createTimeout = function(attempt, opts) {
timeout = Math.min(timeout, opts.maxTimeout);
return timeout;
-}; \ No newline at end of file
+};
diff --git a/node_modules/retry/lib/retry_operation.js b/node_modules/retry/lib/retry_operation.js
index f24d2d5a4..52b895544 100644
--- a/node_modules/retry/lib/retry_operation.js
+++ b/node_modules/retry/lib/retry_operation.js
@@ -1,4 +1,4 @@
-function RetryOperation(timeouts) {
+function RetryOperation(timeouts, retryForever) {
this._timeouts = timeouts;
this._fn = null;
this._errors = [];
@@ -6,6 +6,10 @@ function RetryOperation(timeouts) {
this._operationTimeout = null;
this._operationTimeoutCb = null;
this._timeout = null;
+
+ if (!!retryForever) {
+ this._cachedTimeouts = this._timeouts.slice(0);
+ }
}
module.exports = RetryOperation;
@@ -22,20 +26,27 @@ RetryOperation.prototype.retry = function(err) {
var timeout = this._timeouts.shift();
if (timeout === undefined) {
- return false;
+ 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;
+ }
}
- this._attempts++;
-
var self = this;
setTimeout(function() {
- self._fn(self._attempts);
+ self._attempts++;
if (self._operationTimeoutCb) {
self._timeout = setTimeout(function() {
self._operationTimeoutCb(self._attempts);
}, self._operationTimeout);
}
+
+ self._fn(self._attempts);
}, timeout);
return true;
@@ -53,14 +64,14 @@ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
}
}
- this._fn(this._attempts);
-
var self = this;
if (this._operationTimeoutCb) {
this._timeout = setTimeout(function() {
self._operationTimeoutCb();
}, self._operationTimeout);
}
+
+ this._fn(this._attempts);
};
RetryOperation.prototype.try = function(fn) {
@@ -106,4 +117,4 @@ RetryOperation.prototype.mainError = function() {
}
return mainError;
-}; \ No newline at end of file
+};
diff --git a/node_modules/retry/package.json b/node_modules/retry/package.json
index 1eb375cc3..9cf199373 100644
--- a/node_modules/retry/package.json
+++ b/node_modules/retry/package.json
@@ -1,36 +1,36 @@
{
"_args": [
[
- "retry@~0.6.1",
+ "retry@~0.7.0",
"/Users/rebecca/code/npm"
]
],
- "_from": "retry@>=0.6.1 <0.7.0",
- "_id": "retry@0.6.1",
+ "_from": "retry@>=0.7.0 <0.8.0",
+ "_id": "retry@0.7.0",
"_inCache": true,
"_location": "/retry",
+ "_nodeVersion": "0.10.33",
"_npmUser": {
"email": "tim@debuggable.com",
"name": "tim-kos"
},
- "_npmVersion": "1.4.9",
+ "_npmVersion": "2.1.7",
"_phantomChildren": {},
"_requested": {
"name": "retry",
- "raw": "retry@~0.6.1",
- "rawSpec": "~0.6.1",
+ "raw": "retry@~0.7.0",
+ "rawSpec": "~0.7.0",
"scope": null,
- "spec": ">=0.6.1 <0.7.0",
+ "spec": ">=0.7.0 <0.8.0",
"type": "range"
},
"_requiredBy": [
- "/",
- "/npm-registry-client"
+ "/"
],
- "_resolved": "https://registry.npmjs.org/retry/-/retry-0.6.1.tgz",
- "_shasum": "fdc90eed943fde11b893554b8cc63d0e899ba918",
+ "_resolved": "https://registry.npmjs.org/retry/-/retry-0.7.0.tgz",
+ "_shasum": "dc86eeb960af9acb662896918be4254c1acf6379",
"_shrinkwrap": null,
- "_spec": "retry@~0.6.1",
+ "_spec": "retry@~0.7.0",
"_where": "/Users/rebecca/code/npm",
"author": {
"email": "tim@debuggable.com",
@@ -50,13 +50,16 @@
"lib": "./lib"
},
"dist": {
- "shasum": "fdc90eed943fde11b893554b8cc63d0e899ba918",
- "tarball": "http://registry.npmjs.org/retry/-/retry-0.6.1.tgz"
+ "shasum": "dc86eeb960af9acb662896918be4254c1acf6379",
+ "tarball": "http://registry.npmjs.org/retry/-/retry-0.7.0.tgz"
},
"engines": {
"node": "*"
},
+ "gitHead": "24d1e61f57423286e2d47fedd48876450a19a923",
"homepage": "https://github.com/tim-kos/node-retry",
+ "installable": true,
+ "license": "MIT",
"main": "index",
"maintainers": [
{
@@ -70,5 +73,6 @@
"type": "git",
"url": "git://github.com/tim-kos/node-retry.git"
},
- "version": "0.6.1"
+ "scripts": {},
+ "version": "0.7.0"
}
diff --git a/node_modules/retry/test/integration/test-retry-operation.js b/node_modules/retry/test/integration/test-retry-operation.js
index d873d1fa8..cecfa3b73 100644
--- a/node_modules/retry/test/integration/test-retry-operation.js
+++ b/node_modules/retry/test/integration/test-retry-operation.js
@@ -77,4 +77,30 @@ var retry = require(common.dir.lib + '/retry');
};
fn();
-})(); \ No newline at end of file
+})();
+
+(function testRetryForever() {
+ var error = new Error('some error');
+ var operation = retry.operation({ retries: 3, forever: true });
+ var attempts = 0;
+
+ var finalCallback = fake.callback('finalCallback');
+ fake.expectAnytime(finalCallback);
+
+ var fn = function() {
+ operation.attempt(function(currentAttempt) {
+ attempts++;
+ assert.equal(currentAttempt, attempts);
+ if (attempts !== 6 && operation.retry(error)) {
+ return;
+ }
+
+ assert.strictEqual(attempts, 6);
+ assert.strictEqual(operation.attempts(), attempts);
+ assert.strictEqual(operation.mainError(), error);
+ finalCallback();
+ });
+ };
+
+ fn();
+})();