3#include <boost/asio.hpp>
9#include "crow/logging.h"
21 using key = std::pair<dumb_timer_queue*, int>;
30 unsigned int index =
static_cast<unsigned>(k.second - self->step_);
31 if (index < self->dq_.size())
32 self->dq_[index].second =
nullptr;
36 key
add(std::function<
void()> f)
38 dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
39 int ret = step_+dq_.size()-1;
41 CROW_LOG_DEBUG <<
"timer add inside: " <<
this <<
' ' << ret ;
51 auto now = std::chrono::steady_clock::now();
54 auto& x = dq_.front();
55 if (now - x.first < std::chrono::seconds(tick))
59 CROW_LOG_DEBUG <<
"timer call: " <<
this <<
' ' << step_;
68 void set_io_service(boost::asio::io_service& io_service)
70 io_service_ = &io_service;
73 dumb_timer_queue() noexcept
78 boost::asio::io_service* io_service_{};
79 std::deque<std::pair<
decltype(std::chrono::steady_clock::now()), std::function<
void()>>> dq_;
Fast timer queue for fixed tick value.
Definition: dumb_timer_queue.h:18
void process()
Process the queue: take functions out in time intervals and execute them.
Definition: dumb_timer_queue.h:46
key add(std::function< void()> f)
Add a function to the queue.
Definition: dumb_timer_queue.h:36