Token bucket rate limit algorithm example
#include <atomic>
#include <iostream>
int main(int argc, char** argv)
{
std::cout << "Press Enter to stop..." << std::endl;
std::atomic<bool> stop(false);
std::thread worker = std::thread([&stop, &tb]()
{
while (!stop)
{
else
}
});
std::cin.get();
stop = true;
worker.join();
return 0;
}
static void Yield() noexcept
Yield to other threads.
uint64_t seconds() const noexcept
Get total seconds of the current timestamp.
Token bucket rate limit algorithm.
bool Consume(uint64_t tokens=1)
Try to consume the given count of tokens.
Token bucket rate limit algorithm definition.