1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00
polybar/include/services/event_throttler.hpp
2016-06-21 04:23:28 +02:00

31 lines
774 B
C++

#pragma once
#include <chrono>
#include <deque>
#include <memory>
#include <string>
namespace event_throttler
{
typedef std::chrono::duration<double, std::milli> timewindow_t;
typedef std::chrono::high_resolution_clock timepoint_clock_t;
typedef event_throttler::timepoint_clock_t::time_point timepoint_t;
typedef std::deque<event_throttler::timepoint_t> queue_t;
typedef std::size_t limit_t;
}
class EventThrottler
{
event_throttler::queue_t event_queue;
event_throttler::limit_t passthrough_limit;
event_throttler::timewindow_t timewindow;
protected:
void expire();
public:
explicit EventThrottler(int limit, event_throttler::timewindow_t timewindow)
: passthrough_limit(limit), timewindow(timewindow) {}
bool passthrough();
};