RateLimiter
RateLimiter Class
Handles creation and destruction of TokenBuckets by key.
Constructor Summary
Public Constructor | ||
public |
constructor(config: object) Creates a RateLimiter object. |
Method Summary
Public Methods | ||
public |
decrementTokens(key: string, amount: integer): integer Appropriately decrements the remaining token availability when called and returns the remainder. |
|
public |
destroy() Cleans up all TokenBuckets and nulls the array. |
|
public |
getTokensRemaining(key: string): integer Returns the remaining request count for the given key. |
Public Constructors
public constructor(config: object) source
Creates a RateLimiter object.
Params:
Name | Type | Attribute | Description |
config | object | configuration values |
|
config.limit | integer | The max amount of tokens per incrementInterval. |
|
config.incrementInterval | integer | The time in ms before tokens will increment. |
|
config.increment | integer | The amount of tokens that will increment each incrementInterval. |
Public Methods
public decrementTokens(key: string, amount: integer): integer source
Appropriately decrements the remaining token availability when called and returns the remainder.
Params:
Name | Type | Attribute | Description |
key | string | The identifier for the request |
|
amount | integer |
|
The number to decrement by |
Return:
integer | Remaining request count |