Comparing version 1.2.1 to 1.2.2
@@ -14,2 +14,3 @@ const ms = require('ms'); | ||
const states = ['closed', 'open', 'half open']; | ||
const Promise = require('bluebird'); | ||
@@ -73,8 +74,9 @@ | ||
if (currentState === states[2]) { | ||
currentCooldown = Math.min(currentCooldown * (failures + 1), config.maxCooldown); | ||
} | ||
function catchError(err) { | ||
failures++; | ||
lastFailure = Date.now(); | ||
if (currentState === states[2]) { | ||
currentCooldown = Math.min(currentCooldown * failures, config.maxCooldown); | ||
} | ||
originalCallback(err); | ||
@@ -81,0 +83,0 @@ } |
{ | ||
"name": "disyuntor", | ||
"description": "A circuit-breaker implementation with exponential backoff.", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -64,2 +64,17 @@ const disyuntor = require('./..'); | ||
it('should allow only one attempt on the half-open state', function (done) { | ||
sut(() => { | ||
setTimeout(() => { | ||
async.parallel([ | ||
done => sut(err => done(null, err)), | ||
done => sut(err => done(null, err)), | ||
], (err, errs) => { | ||
assert.match(errs[0].message, /test\.func: specified timeout of 10ms was reached/); | ||
assert.match(errs[1].message, /test\.func: the circuit-breaker is open/); | ||
done(); | ||
}); | ||
}, 200); | ||
}); | ||
}); | ||
it('should backoff on multiple failures', function (done) { | ||
@@ -66,0 +81,0 @@ async.series([ |
Sorry, the diff of this file is not supported yet
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
21991
522