29 lines
723 B
C++
29 lines
723 B
C++
#pragma once
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/bind.hpp>
|
|
|
|
namespace acs
|
|
{
|
|
class loop;
|
|
class await_timer
|
|
{
|
|
loop* loop_;
|
|
boost::asio::deadline_timer timer_;
|
|
std::function<void(const boost::system::error_code&)> user_cb_;
|
|
void callback_handler(const boost::system::error_code& ec);
|
|
public:
|
|
explicit await_timer();
|
|
template <typename F>
|
|
void defer_with(int duration, F&& func)
|
|
{
|
|
user_cb_ = func;
|
|
timer_.expires_from_now(boost::posix_time::millisec(duration));
|
|
timer_.async_wait(boost::bind(
|
|
&await_timer::callback_handler, this, boost::asio::placeholders::error));
|
|
}
|
|
};
|
|
|
|
|
|
}
|