TokenBucket
TokenBucket
Handles how many tokens are available at any given time based on the configuration set and the token bucket algorithm.
Constructor Summary
Public Constructor | ||
public |
constructor(config: object) Creates a TokenBucket object. |
Method Summary
Public Methods | ||
public |
decrementTokens(amount: integer): integer Decrements the amount of tokens available based on amount and returns the value. |
|
public |
destroy() Cleans up the interval set by the constructor. |
|
public |
getTokensRemaining(): integer Returns the currently available tokens. |
Public Constructors
public constructor(config: object) source
Creates a TokenBucket 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(amount: integer): integer source
Decrements the amount of tokens available based on amount and returns the value.
Params:
Name | Type | Attribute | Description |
amount | integer |
|
The number to decrement by |
Return:
integer | The remaining available requests for the identifier |
public getTokensRemaining(): integer source
Returns the currently available tokens.
Return:
integer | The remaining available requests for the identifier |