2016-11-20 17:04:31 -05:00
|
|
|
#include <thread>
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "utils/throttle.hpp"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
namespace throttle_util {
|
|
|
|
namespace strategy {
|
|
|
|
/**
|
|
|
|
* Only pass events when there are slots available
|
|
|
|
*/
|
|
|
|
bool try_once_or_leave_yolo::operator()(queue& q, limit l, timewindow) {
|
|
|
|
if (q.size() >= l)
|
|
|
|
return false;
|
|
|
|
q.emplace_back(timepoint_clock::now());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If no slots are available, wait the required
|
|
|
|
* amount of time for a slot to become available
|
|
|
|
* then let the event pass
|
|
|
|
*/
|
|
|
|
bool wait_patiently_by_the_door::operator()(queue& q, limit l, timewindow) {
|
|
|
|
auto now = timepoint_clock::now();
|
|
|
|
q.emplace_back(now);
|
|
|
|
if (q.size() >= l) {
|
2016-11-20 17:04:31 -05:00
|
|
|
std::this_thread::sleep_for(now - q.front());
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|