#pragma once #include #include #include #include #include #include "common.hpp" #include "utils/mixins.hpp" POLYBAR_NS namespace chrono = std::chrono; using namespace std::chrono_literals; class taskqueue : non_copyable_mixin { public: struct deferred : non_copyable_mixin { using duration = chrono::milliseconds; using timepoint = chrono::time_point; using callback = function; explicit deferred(string&& id, timepoint&& tp, callback&& fn) : id(forward(id)), when(forward(tp)), func(forward(fn)) {} const string id; const timepoint when; const callback func; }; public: using make_type = unique_ptr; static make_type make(); explicit taskqueue(); ~taskqueue(); void defer(string&& id, deferred::duration&& ms, deferred::callback&& fn); void defer_unique(string&& id, deferred::duration&& ms, deferred::callback&& fn); bool has_deferred(string&& id); protected: void tick(); private: std::thread m_thread; std::mutex m_lock; std::condition_variable m_hold; std::atomic_bool m_active{true}; vector> m_deferred; }; POLYBAR_NS_END