#include <userver/utils/token_bucket.hpp>
Thread safe ratelimiter
Definition at line 16 of file token_bucket.hpp.
|
static TokenBucket | MakeUnbounded () noexcept |
| Create an initially unbounded token bucket (largest size, instant refill)
|
|
static double | GetRatePs (Duration interval) |
| Get rate for specified update interval (updates per second)
|
|
◆ Duration
using utils::TokenBucket::Duration = std::chrono::steady_clock::duration |
◆ TimePoint
using utils::TokenBucket::TimePoint = std::chrono::steady_clock::time_point |
◆ TokenBucket()
utils::TokenBucket::TokenBucket |
( |
size_t | max_size, |
|
|
Duration | single_token_update_interval ) |
Start with max_size tokens and add 1 token each single_token_update_interval up to max_size. Zero duration means "no limit".
◆ Obtain()
bool utils::TokenBucket::Obtain |
( |
| ) |
|
- Returns
- true if token was successfully obtained
◆ ObtainAll()
bool utils::TokenBucket::ObtainAll |
( |
size_t | count | ) |
|
- Returns
- true if the requested number of tokens was successfully obtained
◆ SetInstantRefillPolicy()
void utils::TokenBucket::SetInstantRefillPolicy |
( |
| ) |
|
Set refill policy to "instant refill".
Obtain does not deplete the bucket in this mode. Equivalent to amount=1, interval=zero()
policy.
◆ SetUpdateInterval()
void utils::TokenBucket::SetUpdateInterval |
( |
Duration | single_token_update_interval | ) |
|
Add 1 token each token_update_interval. Zero duration means "no limit".
The documentation for this class was generated from the following file: