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-17 01:00:55 +0300
committerRebecca Turner <me@re-becca.org>2015-09-18 01:20:24 +0300
commitebb92caff6127bdc07404f87f48803f141317a1d (patch)
tree8c2238ce8379dad927a4cf50a9cdcad0c92cfdb9 /node_modules/retry
parent54321cff03667cc101e16bc4cead2a7d1fc90ddd (diff)
retry@0.8.0
Diffstat (limited to 'node_modules/retry')
-rw-r--r--node_modules/retry/Readme.md17
-rw-r--r--node_modules/retry/lib/retry.js42
-rw-r--r--node_modules/retry/package.json26
-rw-r--r--node_modules/retry/test/integration/test-retry-wrap.js77
4 files changed, 149 insertions, 13 deletions
diff --git a/node_modules/retry/Readme.md b/node_modules/retry/Readme.md
index f044025c0..09d9c8a81 100644
--- a/node_modules/retry/Readme.md
+++ b/node_modules/retry/Readme.md
@@ -110,6 +110,21 @@ Returns a new `timeout` (integer in milliseconds) based on the given parameters.
`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).
+### retry.wrap(obj, [options], [methodNames])
+
+Wrap all functions of the `obj` with retry. Optionally you can pass operation options and
+an array of method names which need to be wrapped.
+
+```
+retry.wrap(obj)
+
+retry.wrap(obj, ['method1', 'method2']);
+
+retry.wrap(obj, {retries: 3});
+
+retry.wrap(obj, {retries: 3}, ['method1', 'method2']);
+```
+The `options` object can take any options that the usual call to `retry.operation` can take.
### new RetryOperation(timeouts)
@@ -167,6 +182,8 @@ retry is licensed under the MIT license.
#Changelog
+0.7.0 Some bugfixes 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).
+
0.6.0 Introduced optional timeOps parameter for the attempt() function which is an object having a property timeout in miliseconds and a property cb callback function. Whenever your retry operation takes longer than timeout to execute, the timeout callback function cb is called.
0.5.0 Some minor refactorings.
diff --git a/node_modules/retry/lib/retry.js b/node_modules/retry/lib/retry.js
index 646670022..94685652c 100644
--- a/node_modules/retry/lib/retry.js
+++ b/node_modules/retry/lib/retry.js
@@ -50,3 +50,45 @@ exports.createTimeout = function(attempt, opts) {
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/node_modules/retry/package.json b/node_modules/retry/package.json
index 9cf199373..4f4664e84 100644
--- a/node_modules/retry/package.json
+++ b/node_modules/retry/package.json
@@ -1,12 +1,12 @@
{
"_args": [
[
- "retry@~0.7.0",
+ "retry@~0.8.0",
"/Users/rebecca/code/npm"
]
],
- "_from": "retry@>=0.7.0 <0.8.0",
- "_id": "retry@0.7.0",
+ "_from": "retry@>=0.8.0 <0.9.0",
+ "_id": "retry@0.8.0",
"_inCache": true,
"_location": "/retry",
"_nodeVersion": "0.10.33",
@@ -18,19 +18,19 @@
"_phantomChildren": {},
"_requested": {
"name": "retry",
- "raw": "retry@~0.7.0",
- "rawSpec": "~0.7.0",
+ "raw": "retry@~0.8.0",
+ "rawSpec": "~0.8.0",
"scope": null,
- "spec": ">=0.7.0 <0.8.0",
+ "spec": ">=0.8.0 <0.9.0",
"type": "range"
},
"_requiredBy": [
"/"
],
- "_resolved": "https://registry.npmjs.org/retry/-/retry-0.7.0.tgz",
- "_shasum": "dc86eeb960af9acb662896918be4254c1acf6379",
+ "_resolved": "https://registry.npmjs.org/retry/-/retry-0.8.0.tgz",
+ "_shasum": "2367628dc0edb247b1eab649dc53ac8628ac2d5f",
"_shrinkwrap": null,
- "_spec": "retry@~0.7.0",
+ "_spec": "retry@~0.8.0",
"_where": "/Users/rebecca/code/npm",
"author": {
"email": "tim@debuggable.com",
@@ -50,13 +50,13 @@
"lib": "./lib"
},
"dist": {
- "shasum": "dc86eeb960af9acb662896918be4254c1acf6379",
- "tarball": "http://registry.npmjs.org/retry/-/retry-0.7.0.tgz"
+ "shasum": "2367628dc0edb247b1eab649dc53ac8628ac2d5f",
+ "tarball": "http://registry.npmjs.org/retry/-/retry-0.8.0.tgz"
},
"engines": {
"node": "*"
},
- "gitHead": "24d1e61f57423286e2d47fedd48876450a19a923",
+ "gitHead": "9446e803d6a41ae08732a4a215ae5bf1ff1ccfdd",
"homepage": "https://github.com/tim-kos/node-retry",
"installable": true,
"license": "MIT",
@@ -74,5 +74,5 @@
"url": "git://github.com/tim-kos/node-retry.git"
},
"scripts": {},
- "version": "0.7.0"
+ "version": "0.8.0"
}
diff --git a/node_modules/retry/test/integration/test-retry-wrap.js b/node_modules/retry/test/integration/test-retry-wrap.js
new file mode 100644
index 000000000..7ca8bc7eb
--- /dev/null
+++ b/node_modules/retry/test/integration/test-retry-wrap.js
@@ -0,0 +1,77 @@
+var common = require('../common');
+var assert = common.assert;
+var fake = common.fake.create();
+var retry = require(common.dir.lib + '/retry');
+
+function getLib() {
+ return {
+ fn1: function() {},
+ fn2: function() {},
+ fn3: function() {}
+ };
+}
+
+(function wrapAll() {
+ var lib = getLib();
+ retry.wrap(lib);
+ assert.equal(lib.fn1.name, 'retryWrapper');
+ assert.equal(lib.fn2.name, 'retryWrapper');
+ assert.equal(lib.fn3.name, 'retryWrapper');
+}());
+
+(function wrapAllPassOptions() {
+ var lib = getLib();
+ retry.wrap(lib, {retries: 2});
+ assert.equal(lib.fn1.name, 'retryWrapper');
+ assert.equal(lib.fn2.name, 'retryWrapper');
+ assert.equal(lib.fn3.name, 'retryWrapper');
+ assert.equal(lib.fn1.options.retries, 2);
+ assert.equal(lib.fn2.options.retries, 2);
+ assert.equal(lib.fn3.options.retries, 2);
+}());
+
+(function wrapDefined() {
+ var lib = getLib();
+ retry.wrap(lib, ['fn2', 'fn3']);
+ assert.notEqual(lib.fn1.name, 'retryWrapper');
+ assert.equal(lib.fn2.name, 'retryWrapper');
+ assert.equal(lib.fn3.name, 'retryWrapper');
+}());
+
+(function wrapDefinedAndPassOptions() {
+ var lib = getLib();
+ retry.wrap(lib, {retries: 2}, ['fn2', 'fn3']);
+ assert.notEqual(lib.fn1.name, 'retryWrapper');
+ assert.equal(lib.fn2.name, 'retryWrapper');
+ assert.equal(lib.fn3.name, 'retryWrapper');
+ assert.equal(lib.fn2.options.retries, 2);
+ assert.equal(lib.fn3.options.retries, 2);
+}());
+
+(function runWrappedWithoutError() {
+ var callbackCalled;
+ var lib = {method: function(a, b, callback) {
+ assert.equal(a, 1);
+ assert.equal(b, 2);
+ assert.equal(typeof callback, 'function');
+ callback();
+ }};
+ retry.wrap(lib);
+ lib.method(1, 2, function() {
+ callbackCalled = true;
+ });
+ assert.ok(callbackCalled);
+}());
+
+(function runWrappedWithError() {
+ var callbackCalled;
+ var lib = {method: function(callback) {
+ callback(new Error('Some error'));
+ }};
+ retry.wrap(lib, {retries: 1});
+ lib.method(function(err) {
+ callbackCalled = true;
+ assert.ok(err instanceof Error);
+ });
+ assert.ok(!callbackCalled);
+}());