diff --git a/include/components/taskqueue.hpp b/include/components/taskqueue.hpp index 33fb806f..7979fea3 100644 --- a/include/components/taskqueue.hpp +++ b/include/components/taskqueue.hpp @@ -17,10 +17,11 @@ using namespace std::chrono_literals; class taskqueue : non_copyable_mixin { public: struct deferred : non_copyable_mixin { - using timepoint = chrono::time_point; + using duration = chrono::milliseconds; + using timepoint = chrono::time_point; using callback = function; - explicit deferred(string&& id, timepoint::time_point&& tp, callback&& fn) + explicit deferred(string&& id, timepoint&& tp, callback&& fn) : id(forward(id)), when(forward(tp)), func(forward(fn)) {} const string id; @@ -35,8 +36,8 @@ class taskqueue : non_copyable_mixin { explicit taskqueue(); ~taskqueue(); - void defer(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn); - void defer_unique(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn); + 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); diff --git a/src/components/taskqueue.cpp b/src/components/taskqueue.cpp index e8c4b9a0..93817260 100644 --- a/src/components/taskqueue.cpp +++ b/src/components/taskqueue.cpp @@ -44,22 +44,22 @@ taskqueue::~taskqueue() { } } -void taskqueue::defer(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn) { +void taskqueue::defer(string&& id, deferred::duration&& ms, deferred::callback&& fn) { std::unique_lock guard(m_lock); - auto when = chrono::time_point_cast(deferred::timepoint::clock::now() + ms); + auto when = chrono::time_point_cast(deferred::timepoint::clock::now() + ms); m_deferred.emplace_back(make_unique(forward(id), move(when), forward(fn))); guard.unlock(); m_hold.notify_one(); } -void taskqueue::defer_unique(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn) { +void taskqueue::defer_unique(string&& id, deferred::duration&& ms, deferred::callback&& fn) { std::unique_lock guard(m_lock); for (auto it = m_deferred.rbegin(); it != m_deferred.rend(); ++it) { if ((*it)->id == id) { m_deferred.erase(std::remove(m_deferred.begin(), m_deferred.end(), (*it)), m_deferred.end()); } } - auto when = chrono::time_point_cast(deferred::timepoint::clock::now() + ms); + auto when = chrono::time_point_cast(deferred::timepoint::clock::now() + ms); m_deferred.emplace_back(make_unique(forward(id), move(when), forward(fn))); guard.unlock(); m_hold.notify_one();