aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/retry
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/retry')
-rw-r--r--deps/npm/node_modules/retry/Readme.md18
-rw-r--r--deps/npm/node_modules/retry/example/dns.js2
-rw-r--r--deps/npm/node_modules/retry/example/stop.js40
-rw-r--r--deps/npm/node_modules/retry/lib/retry.js4
-rw-r--r--deps/npm/node_modules/retry/lib/retry_operation.js9
-rw-r--r--deps/npm/node_modules/retry/package.json55
-rw-r--r--deps/npm/node_modules/retry/test/integration/test-forever.js24
-rw-r--r--deps/npm/node_modules/retry/test/integration/test-retry-operation.js70
8 files changed, 195 insertions, 27 deletions
diff --git a/deps/npm/node_modules/retry/Readme.md b/deps/npm/node_modules/retry/Readme.md
index 26e50a3a7f..eee05f7bb6 100644
--- a/deps/npm/node_modules/retry/Readme.md
+++ b/deps/npm/node_modules/retry/Readme.md
@@ -78,7 +78,7 @@ milliseconds. If `options` is an array, a copy of that array is returned.
The formula used to calculate the individual timeouts is:
```
-var Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout);
+Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout)
```
Have a look at [this article][article] for a better explanation of approach.
@@ -120,11 +120,11 @@ an array of method names which need to be wrapped.
```
retry.wrap(obj)
-retry.wrap(obj, ['method1', 'method2']);
+retry.wrap(obj, ['method1', 'method2'])
-retry.wrap(obj, {retries: 3});
+retry.wrap(obj, {retries: 3})
-retry.wrap(obj, {retries: 3}, ['method1', 'method2']);
+retry.wrap(obj, {retries: 3}, ['method1', 'method2'])
```
The `options` object can take any options that the usual call to `retry.operation` can take.
@@ -139,7 +139,7 @@ Available options:
If `forever` is true, the following changes happen:
* `RetryOperation.errors()` will only output an array of one item: the last error.
-* `RetryOperation` will repeatedly use the last item in the `timeouts` array.
+* `RetryOperation` will repeatedly use the `timeouts` array. Once all of its timeouts have been used up, it restarts with the first timeout, then uses the second and so on.
#### retryOperation.errors()
@@ -181,6 +181,10 @@ has been reached.
Otherwise it returns `true`, and retries the operation after the timeout for
the current attempt number.
+#### retryOperation.stop()
+
+Allows you to stop the operation being retried. Useful for aborting the operation on a fatal error etc.
+
#### retryOperation.attempts()
Returns an int representing the number of attempts it took to call `fn` before it was successful.
@@ -192,6 +196,10 @@ retry is licensed under the MIT license.
# Changelog
+0.10.0 Adding `stop` functionality, thanks to @maxnachlinger.
+
+0.9.0 Adding `unref` functionality, thanks to @satazor.
+
0.8.0 Implementing retry.wrap.
0.7.0 Some bug fixes and made retry.createTimeout() public. Fixed issues [#10](https://github.com/tim-kos/node-retry/issues/10), [#12](https://github.com/tim-kos/node-retry/issues/12), and [#13](https://github.com/tim-kos/node-retry/issues/13).
diff --git a/deps/npm/node_modules/retry/example/dns.js b/deps/npm/node_modules/retry/example/dns.js
index d6351e9d05..446729b6f9 100644
--- a/deps/npm/node_modules/retry/example/dns.js
+++ b/deps/npm/node_modules/retry/example/dns.js
@@ -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/deps/npm/node_modules/retry/example/stop.js b/deps/npm/node_modules/retry/example/stop.js
new file mode 100644
index 0000000000..e1ceafeeba
--- /dev/null
+++ b/deps/npm/node_modules/retry/example/stop.js
@@ -0,0 +1,40 @@
+var retry = require('../lib/retry');
+
+function attemptAsyncOperation(someInput, cb) {
+ var opts = {
+ retries: 2,
+ factor: 2,
+ minTimeout: 1 * 1000,
+ maxTimeout: 2 * 1000,
+ randomize: true
+ };
+ var operation = retry.operation(opts);
+
+ operation.attempt(function(currentAttempt) {
+ failingAsyncOperation(someInput, function(err, result) {
+
+ if (err && err.message === 'A fatal error') {
+ operation.stop();
+ return cb(err);
+ }
+
+ if (operation.retry(err)) {
+ return;
+ }
+
+ cb(operation.mainError(), operation.errors(), result);
+ });
+ });
+}
+
+attemptAsyncOperation('test input', function(err, errors, result) {
+ console.warn('err:');
+ console.log(err);
+
+ console.warn('result:');
+ console.log(result);
+});
+
+function failingAsyncOperation(input, cb) {
+ return setImmediate(cb.bind(null, new Error('A fatal error')));
+}
diff --git a/deps/npm/node_modules/retry/lib/retry.js b/deps/npm/node_modules/retry/lib/retry.js
index 02ab14729b..77428cfd00 100644
--- a/deps/npm/node_modules/retry/lib/retry.js
+++ b/deps/npm/node_modules/retry/lib/retry.js
@@ -33,6 +33,10 @@ exports.timeouts = function(options) {
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;
diff --git a/deps/npm/node_modules/retry/lib/retry_operation.js b/deps/npm/node_modules/retry/lib/retry_operation.js
index ad96efbdf3..2b3db8e177 100644
--- a/deps/npm/node_modules/retry/lib/retry_operation.js
+++ b/deps/npm/node_modules/retry/lib/retry_operation.js
@@ -19,6 +19,15 @@ function RetryOperation(timeouts, options) {
}
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);
diff --git a/deps/npm/node_modules/retry/package.json b/deps/npm/node_modules/retry/package.json
index 9d2283a398..73a2819ede 100644
--- a/deps/npm/node_modules/retry/package.json
+++ b/deps/npm/node_modules/retry/package.json
@@ -1,41 +1,54 @@
{
"_args": [
[
- "retry@latest",
- "/Users/rebecca/code/npm"
+ {
+ "raw": "retry@0.10.0",
+ "scope": null,
+ "escapedName": "retry",
+ "name": "retry",
+ "rawSpec": "0.10.0",
+ "spec": "0.10.0",
+ "type": "version"
+ },
+ "/Users/zkat/Documents/code/npm"
]
],
- "_from": "retry@latest",
- "_id": "retry@0.9.0",
+ "_from": "retry@0.10.0",
+ "_id": "retry@0.10.0",
"_inCache": true,
- "_installable": true,
"_location": "/retry",
"_nodeVersion": "4.2.1",
+ "_npmOperationalInternal": {
+ "host": "packages-12-west.internal.npmjs.com",
+ "tmp": "tmp/retry-0.10.0.tgz_1471682099847_0.5031970851123333"
+ },
"_npmUser": {
- "email": "tim@debuggable.com",
- "name": "tim-kos"
+ "name": "tim-kos",
+ "email": "tim@debuggable.com"
},
"_npmVersion": "2.1.7",
"_phantomChildren": {},
"_requested": {
- "name": "retry",
- "raw": "retry@latest",
- "rawSpec": "latest",
+ "raw": "retry@0.10.0",
"scope": null,
- "spec": "latest",
- "type": "tag"
+ "escapedName": "retry",
+ "name": "retry",
+ "rawSpec": "0.10.0",
+ "spec": "0.10.0",
+ "type": "version"
},
"_requiredBy": [
+ "#USER",
"/"
],
- "_resolved": "https://registry.npmjs.org/retry/-/retry-0.9.0.tgz",
- "_shasum": "6f697e50a0e4ddc8c8f7fb547a9b60dead43678d",
+ "_resolved": "https://registry.npmjs.org/retry/-/retry-0.10.0.tgz",
+ "_shasum": "649e15ca408422d98318161935e7f7d652d435dd",
"_shrinkwrap": null,
- "_spec": "retry@latest",
- "_where": "/Users/rebecca/code/npm",
+ "_spec": "retry@0.10.0",
+ "_where": "/Users/zkat/Documents/code/npm",
"author": {
- "email": "tim@debuggable.com",
"name": "Tim Koschützki",
+ "email": "tim@debuggable.com",
"url": "http://debuggable.com/"
},
"bugs": {
@@ -51,13 +64,13 @@
"lib": "./lib"
},
"dist": {
- "shasum": "6f697e50a0e4ddc8c8f7fb547a9b60dead43678d",
- "tarball": "http://registry.npmjs.org/retry/-/retry-0.9.0.tgz"
+ "shasum": "649e15ca408422d98318161935e7f7d652d435dd",
+ "tarball": "https://registry.npmjs.org/retry/-/retry-0.10.0.tgz"
},
"engines": {
"node": "*"
},
- "gitHead": "1b621cf499ef7647d005e3650006b93a8dbeb986",
+ "gitHead": "0616e6a6ebc49b5a36b619c8f7c414ced8c3813b",
"homepage": "https://github.com/tim-kos/node-retry",
"license": "MIT",
"main": "index",
@@ -75,5 +88,5 @@
"url": "git://github.com/tim-kos/node-retry.git"
},
"scripts": {},
- "version": "0.9.0"
+ "version": "0.10.0"
}
diff --git a/deps/npm/node_modules/retry/test/integration/test-forever.js b/deps/npm/node_modules/retry/test/integration/test-forever.js
new file mode 100644
index 0000000000..b41307cb52
--- /dev/null
+++ b/deps/npm/node_modules/retry/test/integration/test-forever.js
@@ -0,0 +1,24 @@
+var common = require('../common');
+var assert = common.assert;
+var retry = require(common.dir.lib + '/retry');
+
+(function testForeverUsesFirstTimeout() {
+ var operation = retry.operation({
+ retries: 0,
+ minTimeout: 100,
+ maxTimeout: 100,
+ forever: true
+ });
+
+ operation.attempt(function(numAttempt) {
+ console.log('>numAttempt', numAttempt);
+ var err = new Error("foo");
+ if (numAttempt == 10) {
+ operation.stop();
+ }
+
+ if (operation.retry(err)) {
+ return;
+ }
+ });
+})();
diff --git a/deps/npm/node_modules/retry/test/integration/test-retry-operation.js b/deps/npm/node_modules/retry/test/integration/test-retry-operation.js
index cecfa3b731..916936424f 100644
--- a/deps/npm/node_modules/retry/test/integration/test-retry-operation.js
+++ b/deps/npm/node_modules/retry/test/integration/test-retry-operation.js
@@ -104,3 +104,73 @@ var retry = require(common.dir.lib + '/retry');
fn();
})();
+
+(function testRetryForeverNoRetries() {
+ var error = new Error('some error');
+ var delay = 50
+ var operation = retry.operation({
+ retries: null,
+ forever: true,
+ minTimeout: delay,
+ maxTimeout: delay
+ });
+
+ var attempts = 0;
+ var startTime = new Date().getTime();
+
+ var finalCallback = fake.callback('finalCallback');
+ fake.expectAnytime(finalCallback);
+
+ var fn = function() {
+ operation.attempt(function(currentAttempt) {
+ attempts++;
+ assert.equal(currentAttempt, attempts);
+ if (attempts !== 4 && operation.retry(error)) {
+ return;
+ }
+
+ var endTime = new Date().getTime();
+ var minTime = startTime + (delay * 3);
+ var maxTime = minTime + 20 // add a little headroom for code execution time
+ assert(endTime > minTime)
+ assert(endTime < maxTime)
+ assert.strictEqual(attempts, 4);
+ assert.strictEqual(operation.attempts(), attempts);
+ assert.strictEqual(operation.mainError(), error);
+ finalCallback();
+ });
+ };
+
+ fn();
+})();
+
+(function testStop() {
+ var error = new Error('some error');
+ var operation = retry.operation([1, 2, 3]);
+ 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 === 2) {
+ operation.stop();
+
+ assert.strictEqual(attempts, 2);
+ assert.strictEqual(operation.attempts(), attempts);
+ assert.strictEqual(operation.mainError(), error);
+ finalCallback();
+ }
+
+ if (operation.retry(error)) {
+ return;
+ }
+ });
+ };
+
+ fn();
+})();