Comparing version 4.0.0 to 4.1.0
@@ -32,9 +32,2 @@ "use strict"; | ||
class DisyuntorConfig { | ||
constructor(name, thresholdConfig, onBreakerTripEvent, onBreakerCloseEvent, shouldTriggerAsFailure = () => true) { | ||
this.name = name; | ||
this.thresholdConfig = thresholdConfig; | ||
this.onBreakerTripEvent = onBreakerTripEvent; | ||
this.onBreakerCloseEvent = onBreakerCloseEvent; | ||
this.shouldTriggerAsFailure = shouldTriggerAsFailure; | ||
} | ||
/** | ||
@@ -53,3 +46,3 @@ * Convenience method for mixed-bag time objects | ||
else if (typeof input === 'string') { | ||
return ms_1.default(input); | ||
return (0, ms_1.default)(input); | ||
} | ||
@@ -76,3 +69,10 @@ else { | ||
} | ||
constructor(name, thresholdConfig, onBreakerTripEvent, onBreakerCloseEvent, shouldTriggerAsFailure = () => true) { | ||
this.name = name; | ||
this.thresholdConfig = thresholdConfig; | ||
this.onBreakerTripEvent = onBreakerTripEvent; | ||
this.onBreakerCloseEvent = onBreakerCloseEvent; | ||
this.shouldTriggerAsFailure = shouldTriggerAsFailure; | ||
} | ||
} | ||
exports.DisyuntorConfig = DisyuntorConfig; |
@@ -10,3 +10,3 @@ /// <reference types="node" /> | ||
} | ||
declare type PromiseBuilder<T> = (...args: any[]) => Promise<T>; | ||
type PromiseBuilder<T> = (...args: any[]) => Promise<T>; | ||
export declare class Disyuntor extends EventEmitter { | ||
@@ -13,0 +13,0 @@ private config; |
@@ -25,2 +25,5 @@ "use strict"; | ||
class Disyuntor extends events_1.EventEmitter { | ||
get timeout() { | ||
return this.config.thresholdConfig.callTimeoutMs; | ||
} | ||
constructor(params) { | ||
@@ -43,5 +46,2 @@ super(); | ||
} | ||
get timeout() { | ||
return this.config.thresholdConfig.callTimeoutMs; | ||
} | ||
reset() { | ||
@@ -76,3 +76,7 @@ this.failures = 0; | ||
else if (state === State.HalfOpen) { | ||
this.currentCooldown = Math.min(this.currentCooldown * (this.failures + 1), this.config.thresholdConfig.maxCooldownTimeMs); | ||
/* | ||
We add 2 because we're setting the cooldown for the case that the current call fails, and the number of trips we've observed is already equal to this.failures - this.config.thresholdConfig.maxConsecutiveFailures + 1 | ||
*/ | ||
const cooldownMultiplier = this.failures - this.config.thresholdConfig.maxConsecutiveFailures + 2; | ||
this.currentCooldown = Math.min(this.currentCooldown * cooldownMultiplier, this.config.thresholdConfig.maxCooldownTimeMs); | ||
} | ||
@@ -86,3 +90,3 @@ try { | ||
else { | ||
const timeout = Timeout_1.create(this.config.name, this.config.thresholdConfig.callTimeoutMs, promise); | ||
const timeout = (0, Timeout_1.create)(this.config.name, this.config.thresholdConfig.callTimeoutMs, promise); | ||
result = yield Promise.race([timeout, promise]); | ||
@@ -89,0 +93,0 @@ } |
{ | ||
"name": "disyuntor", | ||
"description": "A circuit-breaker implementation with exponential backoff.", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)", | ||
@@ -6,0 +6,0 @@ "repository": { |
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
23541
406