#include <icy/ratelimiter.h>Token bucket rate limiter for throttling message send frequency.
| Return | Name | Description |
|---|---|---|
double | rate | How many messages. |
double | seconds | Over how many seconds. |
double | allowance | Remaining send allowance. |
double rateHow many messages.
double secondsOver how many seconds.
double allowanceRemaining send allowance.
| 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. |
inline
inline RateLimiter(double rate, double seconds)Constructs a token bucket limiter.
rate Maximum number of messages permitted in the window.
seconds Duration of the replenishment window in seconds.
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.
true if sending is allowed, false if the rate limit is exceeded.
| Return | Name | Description |
|---|---|---|
std::chrono::steady_clock::time_point | _lastCheck | |
bool | _started |
std::chrono::steady_clock::time_point _lastCheckbool _started