Skip to content

Commit

Permalink
fixups post review
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jul 3, 2024
1 parent ca46870 commit 12aae13
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/CircuitBreaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export class CircuitBreaker extends EventEmitter {
// a promise that unit tests can await on, as jest's fake timers
// get confused with async flows
_evaluatingPromiseHook: Promise<unknown> | null;
_cbError: boolean;
_failedProbes: boolean;

constructor(config: unknown) {
super();

this._config = validate(config);
this._probes = (this._config.probes || []).map(buildProbe);
this._cbError = false;
this._failedProbes = false;

this._aggregateState = BreakerState.Nominal;
this._stabilizingCounter = 0;
Expand All @@ -51,8 +51,8 @@ export class CircuitBreaker extends EventEmitter {
return this._aggregateState;
}

get probesFailed(): boolean {
return this._cbError;
get failedProbes(): boolean {
return this._failedProbes;
}

start() {
Expand All @@ -68,14 +68,13 @@ export class CircuitBreaker extends EventEmitter {
}

async _evaluate() {
this._failedProbes = false;
this._evaluatingPromiseHook = Promise.allSettled(this._probes.map(p => p.check().catch(() => {
this._cbError = true;
this._failedProbes = true;
})));
await this._evaluatingPromiseHook;
this._evaluatingPromiseHook = null;
if (!this._cbError) {
this._cbError = false;
}

const allOk = this._probes.every(probe => probe.value);
const initialState = this._aggregateState;

Expand Down

0 comments on commit 12aae13

Please sign in to comment.