Comparing version 0.0.1-7 to 0.0.2-1
@@ -8,5 +8,7 @@ exports.RETRY_STRATEGY = RETRY_STRATEGY = {CONSTANT: 0, EXPONENTIAL: 1, LINEAR: 2}; | ||
exports.Re = function Re(options){ | ||
if(!(this instanceof Re)) return Re(options); | ||
exports.Re = Re; | ||
function Re(options){ | ||
if(!(this instanceof Re)) return new Re(options); | ||
var retryStrategy; | ||
@@ -46,10 +48,10 @@ | ||
function Re.prototype.try(operation, callback){ | ||
var fail = createFailCallback(operation, callback); | ||
Re.prototype.try = function(operation, callback){ | ||
var fail = this.createFailCallback(operation, callback); | ||
callback = callback || function () {}; | ||
try{ | ||
operation(self.retry, fail, callback); | ||
operation(this.retry, fail, callback); | ||
} catch(err) { | ||
console.log("EXCEPTIONS BIATCH!") | ||
fail(err); | ||
@@ -59,18 +61,17 @@ } | ||
function Re.prototype.do(operation, callback){ | ||
var fail = createFailCallback(operation, callback); | ||
Re.prototype.do = function(operation, callback){ | ||
var fail = this.createFailCallback(operation, callback); | ||
callback = callback || function () {}; | ||
operation(self.retry, fail, callback); | ||
operation(this.retry, fail, callback); | ||
} | ||
var createFailCallback = function(operation, callback){ | ||
Re.prototype.createFailCallback = function(operation, callback){ | ||
var self = this; | ||
return function(err){ | ||
var self = this, | ||
fail = createFailCallback(operation, callback); | ||
var fail = self.createFailCallback(operation, callback); | ||
self.retry++; | ||
if(this.retry < this.maxRetries){ | ||
if(self.retry < self.maxRetries){ | ||
setTimeout(function(){ | ||
@@ -83,2 +84,4 @@ operation(self.retry, fail, callback); | ||
} | ||
self.retry++; | ||
}; | ||
@@ -85,0 +88,0 @@ }; |
{ | ||
"name": "re", | ||
"description": "Do it again, after a bit.", | ||
"version": "0.0.1-7", | ||
"version": "0.0.2-1", | ||
"main": "./lib/re", | ||
@@ -6,0 +6,0 @@ "keywords": ["utility", "retry", "exponential backoff", "linear backoff"], |
@@ -24,5 +24,5 @@ # Re | ||
if(retryCount < 2) fail(new Error("Not there yet!")); | ||
else callback(retryCount); | ||
else callback(null, retryCount); | ||
}, | ||
function(retryCount){ | ||
function(err, retryCount){ | ||
console.log("It took this many tries: " + retryCount); | ||
@@ -29,0 +29,0 @@ }); |
7429
4
108