Comparing version 0.1.0 to 0.2.0
@@ -14,3 +14,3 @@ var dns = require('dns'); | ||
operation.try(function() { | ||
operation.try(function(currentAttempt) { | ||
dns.resolve(address, function(err, addresses) { | ||
@@ -17,0 +17,0 @@ if (operation.retry(err)) { |
@@ -5,2 +5,3 @@ function RetryOperation(timeouts) { | ||
this._errors = []; | ||
this._attempts = 1; | ||
} | ||
@@ -21,3 +22,4 @@ module.exports = RetryOperation; | ||
setTimeout(this._fn.bind(this), timeout); | ||
this._attempts++; | ||
setTimeout(this._fn.bind(this, this._attempts), timeout); | ||
@@ -29,3 +31,3 @@ return true; | ||
this._fn = fn; | ||
this._fn(); | ||
this._fn(this._attempts); | ||
}; | ||
@@ -37,2 +39,6 @@ | ||
RetryOperation.prototype.attempts = function() { | ||
return this._attempts; | ||
}; | ||
RetryOperation.prototype.mainError = function() { | ||
@@ -39,0 +45,0 @@ if (this._errors.length === 0) { |
@@ -5,3 +5,3 @@ { | ||
"description": "Abstraction for exponential and custom retry strategies for failed operations.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/felixge/node-retry", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -26,3 +26,3 @@ # retry | ||
operation.try(function() { | ||
operation.try(function(currentAttempt) { | ||
dns.resolve(address, function(err, addresses) { | ||
@@ -45,2 +45,3 @@ if (operation.retry(err)) { | ||
backoff. See the API documentation below for all available settings. | ||
currentAttempt is an int representing the number of attempts so far. | ||
@@ -116,3 +117,3 @@ ``` javascript | ||
Defines the function `fn` that is to be retried and executes it for the first | ||
time right away. | ||
time right away. The `fn` function can receive an optional `currentAttempt` callback that represents the number of attempts to execute `fn` so far. | ||
@@ -127,4 +128,8 @@ #### retryOperation.retry(error) | ||
#### retryOperation.attempts() | ||
Returns an int representing the number of attempts it took to call `fn` before it was successful. | ||
## License | ||
retry is licensed under the MIT license. |
@@ -51,3 +51,3 @@ var common = require('../common'); | ||
var operation = retry.operation([1, 2, 3]); | ||
var retries = 0; | ||
var attempts = 0; | ||
@@ -58,9 +58,11 @@ var finalCallback = fake.callback('finalCallback'); | ||
var fn = function() { | ||
operation.try(function() { | ||
operation.try(function(currentAttempt) { | ||
attempts++; | ||
assert.equal(currentAttempt, attempts); | ||
if (operation.retry(error)) { | ||
retries++; | ||
return; | ||
} | ||
assert.strictEqual(retries, 3); | ||
assert.strictEqual(attempts, 4); | ||
assert.strictEqual(operation.attempts(), attempts); | ||
assert.strictEqual(operation.mainError(), error); | ||
@@ -67,0 +69,0 @@ finalCallback(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12417
229
132
2