Comparing version 0.0.8-3 to 0.1.0-0
@@ -60,8 +60,8 @@ (function (){ | ||
Re.prototype.try = function(operation, callback){ | ||
var fail = this.createFailCallback(operation, callback, this.try); | ||
var done = this.createDoneCallback(operation, callback, this.try); | ||
try{ | ||
operation(this.retry, fail, callback); | ||
operation(this.retry, done); | ||
} catch(err) { | ||
fail(err); | ||
done(err); | ||
} | ||
@@ -71,13 +71,16 @@ }; | ||
Re.prototype.do = function(operation, callback){ | ||
var fail = this.createFailCallback(operation, callback, this.do); | ||
var fail = this.createDoneCallback(operation, callback, this.do); | ||
operation(this.retry, fail, callback); | ||
operation(this.retry, done); | ||
}; | ||
Re.prototype.createFailCallback = function(operation, callback, method){ | ||
Re.prototype.createDoneCallback = function(operation, callback, method){ | ||
var self = this; | ||
return function(err){ | ||
var doneArguments = arguments; | ||
callback = callback || function () {}; | ||
if(!err) return setTimeout(function(){callback.apply(null, doneArguments);}, 0); | ||
if(self.retry < self.maxRetries){ | ||
@@ -89,3 +92,3 @@ setTimeout(function(){ | ||
} else { | ||
return callback(err); | ||
return setTimeout(function(){callback.apply(null, doneArguments);}, 0); | ||
} | ||
@@ -92,0 +95,0 @@ |
{ | ||
"name": "re", | ||
"description": "Do it again, after a bit.", | ||
"version": "0.0.8-3", | ||
"version": "0.1.0-0", | ||
"main": "./lib/re", | ||
@@ -6,0 +6,0 @@ "keywords": ["utility", "retry", "exponential backoff", "linear backoff"], |
@@ -20,4 +20,4 @@ # Re | ||
var repeatMe = function(retryCount, fail, callback){ | ||
if(retryCount < 2) fail(new Error("Not there yet!")); | ||
var repeatMe = function(retryCount, done){ | ||
if(retryCount < 2) done(new Error("Not there yet!")); | ||
else callback(null, retryCount); | ||
@@ -31,3 +31,3 @@ }; | ||
## In the Browser | ||
Tested in Chrome. Usage: | ||
Tested in Firefox and Chrome. Usage: | ||
@@ -50,8 +50,8 @@ <script type="text/javascript" src="re.js"></script> | ||
re.try(function(retryCount, fail, callback){ | ||
if(retryCount < 2) fail(new Error("Not there yet!")); | ||
else callback(null, retryCount); | ||
re.try(function(retryCount, done){ | ||
if(retryCount < 2) done(new Error("Not there yet!")); | ||
else done(null, retryCount); | ||
}, | ||
function(err, retryCount){ | ||
console.log("It took this many tries: " + retryCount); | ||
console.log("It took this many retries: " + retryCount); | ||
}); | ||
@@ -66,5 +66,5 @@ | ||
This first function passed to `re.try` should take 3 arguments like this: | ||
This first function passed to `re.try` should take 2 arguments like this: | ||
function operation(retryCount, fail, callback) | ||
function operation(retryCount, done) | ||
@@ -74,11 +74,11 @@ The `retryCount` argument is the number of the current retry. It'll be zero the first time | ||
The `fail` argument is a function to call if you | ||
encounter a fail condition in your operation. This let's us know we need to try again. | ||
If you don't call `fail` and no exception happens, you're done. You can pass an `err` | ||
argument to the `fail` function. | ||
The `done` argument is a function to call when you've completed your operation. | ||
If you encounter an error condition in your operation, pass in the Error object | ||
as the first argument. If you don't encounter an error, pass in a falsy first | ||
argument (null works). If you give us a falsy error and no exception happens, | ||
we call your callback with all the arguments passed into this function. | ||
The `callback` argument is the callback function you passed into `re.try`. It should be | ||
a function that takes an `err` parameter as it's first argument. The rest of the arguments | ||
are up to you. Call this when you succeed. We'll call it with the last exception or whatever | ||
you passed to the last `fail`, when too many failures happen. | ||
The second function passed to `re.try` can take as many arguments as you like but | ||
should always start with an error parameter. This will be called with a falsy first | ||
parameter, if no error happens. | ||
@@ -85,0 +85,0 @@ The `re.do` function is like `re.try` expect it doesn't wrap your operation in |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
28727
9
251
1