in src/eventBucketThrottle.ts [75:101]
private refill(eventName: string) {
let lastFilled: number;
const now = Math.floor(Date.now() / 1000);
// We look up when was the last time we called the refill
// method for this event, if it was never called we set it
// to the current time
if (typeof this.EventFilled[eventName] === "undefined") {
this.EventFilled[eventName] = now;
lastFilled = now;
} else {
lastFilled = this.EventFilled[eventName];
}
// We've already divided by 1000, so this timeDelta will represent
// the number of seconds elapsed since the last time the method was called
const timeDelta = now - lastFilled;
// If we somehow calculate incorrectly the bucket size as something
// over what the potential capacity could be we default to the maxiumum
// bucket size
this.EventBuckets[eventName] = Math.min(
this.capacity,
this.EventBuckets[eventName] + Math.floor(timeDelta * this.fillPerSecond)
);
this.EventFilled[eventName] = now;
}