mirror-chatterino2/src/util/RatelimitBucket.hpp
pajlada 18cb4bd6e5
Massage includes some more (#4294)
* Add `<functional>` include to QStringHash.hpp

This ensures the base `std::hash` template is declared before this
specialization

* Add missing includes to `src/providers/twitch/TwitchAccountManager.hpp`

* Move explicit HelixChatters constructor to the source file

* Remove unused includes & add used includes to NicknamesModel.hpp

* NicknamesModel.hpp: Remove `virtual` when `override` is used

* Add missing QStringHash include to TwitchEmotes.cpp

* Add missing includes to various files

* Print Qt version in cmake step

Technically unrelated, but I'm sneaking it in

* Add changelog entry
2023-01-08 12:07:06 +00:00

43 lines
1,011 B
C++

#pragma once
#include <QList>
#include <QObject>
#include <QString>
#include <functional>
namespace chatterino {
class RatelimitBucket : public QObject
{
public:
RatelimitBucket(int budget, int cooldown,
std::function<void(QString)> callback, QObject *parent);
void send(QString channel);
private:
/**
* @brief budget_ denotes the amount of calls that can be handled before we need to wait for the cooldown
**/
int budget_;
/**
* @brief This is the amount of time in milliseconds it takes for one used up budget to be put back into the bucket for use elsewhere
**/
const int cooldown_;
std::function<void(QString)> callback_;
QList<QString> queue_;
/**
* @brief Run the callback on one entry in the queue.
*
* This will start a timer that runs after cooldown_ milliseconds that
* gives back one "token" to the bucket and calls handleOne again.
**/
void handleOne();
};
} // namespace chatterino