Base module
RateLimiter
Token bucket rate limiter for throttling message send frequency.
RateLimiter
#include <icy/ratelimiter.h>Token bucket rate limiter for throttling message send frequency.
Public Attributes
| Return | Name | Description |
|---|---|---|
double | rate | How many messages. |
double | seconds | Over how many seconds. |
double | allowance | Remaining send allowance. |
rate
double rateHow many messages.
seconds
double secondsOver how many seconds.
allowance
double allowanceRemaining send allowance.
Public Methods
| Return | Name | Description |
|---|---|---|
RateLimiter inline | Constructs a token bucket limiter. | |
bool | canSend inline | Returns true if a message may be sent without exceeding the rate limit. Replenishes the token bucket based on elapsed time since the last check, then consumes one token. Returns false if the bucket is empty. |
RateLimiter
inline
inline RateLimiter(double rate, double seconds)Constructs a token bucket limiter.
Parameters
rateMaximum number of messages permitted in the window.secondsDuration of the replenishment window in seconds.
canSend
inline
inline bool canSend()Returns true if a message may be sent without exceeding the rate limit. Replenishes the token bucket based on elapsed time since the last check, then consumes one token. Returns false if the bucket is empty.
Returns
true if sending is allowed, false if the rate limit is exceeded.
Private Attributes
| Return | Name | Description |
|---|---|---|
std::chrono::steady_clock::time_point | _lastCheck | |
bool | _started |
_lastCheck
std::chrono::steady_clock::time_point _lastCheck_started
bool _started