hystrixjs
Version:
resilience module for NodeJS applications
34 lines (28 loc) • 820 B
JavaScript
import RollingNumberEvent from "./RollingNumberEvent";
export default class CounterBucket {
constructor (windowStart) {
this.windowStart = windowStart;
this.bucketValues = {};
}
get(type) {
if (RollingNumberEvent[type] === undefined) {
throw new Error("invalid event");
}
if (!this.bucketValues[type]) {
this.bucketValues[type] = 0;
}
return this.bucketValues[type];
}
increment(type) {
if (RollingNumberEvent[type] === undefined) {
throw new Error("invalid event");
}
let value = this.bucketValues[type];
if (value) {
value = value + 1;
this.bucketValues[type] = value;
} else {
this.bucketValues[type] = 1;
}
}
}