Home
Base module

RateLimiter

Token bucket rate limiter for throttling message send frequency.

RateLimiter

#include <icy/ratelimiter.h>
class RateLimiter

Defined in src/base/include/icy/ratelimiter.h:23

Token bucket rate limiter for throttling message send frequency.

List of all members

NameKindOwner
ratevariableDeclared here
secondsvariableDeclared here
allowancevariableDeclared here
RateLimiterfunctionDeclared here
canSendfunctionDeclared here
_lastCheckvariableDeclared here
_startedvariableDeclared here

Public Attributes

ReturnNameDescription
doublerateHow many messages.
doublesecondsOver how many seconds.
doubleallowanceRemaining send allowance.

rate

double rate

Defined in src/base/include/icy/ratelimiter.h:26

How many messages.


seconds

double seconds

Defined in src/base/include/icy/ratelimiter.h:27

Over how many seconds.


allowance

double allowance

Defined in src/base/include/icy/ratelimiter.h:28

Remaining send allowance.

Public Methods

ReturnNameDescription
RateLimiter inlineConstructs a token bucket limiter.
boolcanSend inlineReturns 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 = 5.0, double seconds = 6.0)

Defined in src/base/include/icy/ratelimiter.h:33

Constructs a token bucket limiter.

Parameters

  • rate Maximum number of messages permitted in the window.

  • seconds Duration of the replenishment window in seconds.


canSend

inline

inline bool canSend()

Defined in src/base/include/icy/ratelimiter.h:46

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

ReturnNameDescription
std::chrono::steady_clock::time_point_lastCheck
bool_started

_lastCheck

std::chrono::steady_clock::time_point _lastCheck

Defined in src/base/include/icy/ratelimiter.h:76


_started

bool _started

Defined in src/base/include/icy/ratelimiter.h:77