According to boost documentation: For each call to async_wait(), the supplied handler will be called exactly once. The handler will be called when: - The timer has expired. - The timer was cancelled, in which case the handler is passed the error code boost::asio::error::operation_aborted.
for a similar code:
std::unique_ptr<timer> periodSendTimer_;
ContentQueue::ContentQueue(...timer....): periodSendTimer_(timer){}
ContentQueue::~ContentQueue()
{
periodSendTimer_->cancel();
}
void ContentQueue::startSendLoop(const boost::system::error_code& error)
{
if (not error)
{
periodSendTimer_->expires_from_now(boost::posix_time::seconds(1));
periodSendTimer_->async_wait(boost::bind (&ContentQueue::startSendLoop, this, boost::asio::placeholders::error));
}
else if(error == boost::asio::error::operation_aborted)
{.....}
else
{....}
}
My problem is that very very rarely it happens that Destructor is called but in the same time(until timer will be canceled) timer expires(from expires_from_now) and for handler startSendLoop is NOT passed as expected boost::asio::error::operation_aborted.
Any feedback/solution?