in src/eventBucketThrottle.ts [103:130]
public take(eventName: string) {
// In the case of new event we create a new eventBucket for it
// otherwise we calculate the refill rate for an existing event
if (typeof this.EventBuckets[eventName] === "undefined") {
this.EventBuckets[eventName] = this.capacity;
} else {
this.refill(eventName);
}
this.refillTotalBucket();
// We check both that the specific event bucket and the total bucket size
// are greater than 0
if (this.EventBuckets[eventName] > 0 && this.totalBucketSize > 0) {
// Subtract both from the event bucket and the overall bucket
this.EventBuckets[eventName] -= 1;
this.totalBucketSize -= 1;
return true;
} else {
// If we do end up throttling an event
// we keep track of how many times it was
// throttled
this.ThrottledEvents[eventName] =
typeof this.ThrottledEvents[eventName] !== "undefined" ? this.ThrottledEvents[eventName] + 1 : 1;
this.NumberOfThrottledEvents++;
}
return false;
}