# RateLimiter

<a id="ratelimiter"></a>

# RateLimiter

```cpp
#include <icy/ratelimiter.h>

class RateLimiter
```

[Defined in src/base/include/icy/ratelimiter.h:23](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L23)

Token bucket rate limiter for throttling message send frequency.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `double` | [`rate`](#rate)  | How many messages. |
| `double` | [`seconds`](#seconds)  | Over how many seconds. |
| `double` | [`allowance`](#allowance)  | Remaining send allowance. |

---

<a id="rate"></a>

### rate

```cpp
double rate
```

[Defined in src/base/include/icy/ratelimiter.h:26](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L26)

How many messages.

---

<a id="seconds"></a>

### seconds

```cpp
double seconds
```

[Defined in src/base/include/icy/ratelimiter.h:27](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L27)

Over how many seconds.

---

<a id="allowance"></a>

### allowance

```cpp
double allowance
```

[Defined in src/base/include/icy/ratelimiter.h:28](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L28)

Remaining send allowance.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`RateLimiter`](#ratelimiter-1) `inline` | Constructs a token bucket limiter. |
| `bool` | [`canSend`](#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. |

---

<a id="ratelimiter-1"></a>

### RateLimiter

`inline`

```cpp
inline RateLimiter(double rate = 5.0, double seconds = 6.0)
```

[Defined in src/base/include/icy/ratelimiter.h:33](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L33)

Constructs a token bucket limiter.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `rate` | `double` | Maximum number of messages permitted in the window. |
| `seconds` | `double` | Duration of the replenishment window in seconds. |

---

<a id="cansend"></a>

### canSend

`inline`

```cpp
inline bool canSend()
```

[Defined in src/base/include/icy/ratelimiter.h:46](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L46)

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`](#_lastcheck)  |  |
| `bool` | [`_started`](#_started)  |  |

---

<a id="_lastcheck"></a>

### _lastCheck

```cpp
std::chrono::steady_clock::time_point _lastCheck
```

[Defined in src/base/include/icy/ratelimiter.h:76](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L76)

---

<a id="_started"></a>

### _started

```cpp
bool _started
```

[Defined in src/base/include/icy/ratelimiter.h:77](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ratelimiter.h#L77)
