You mentioned that calling the cancel () function on a timer causes an immediate call to the function passed to async_wait. This is expected behavior, but remember that you can check the error passed to the timer handler to determine if the timer has been canceled. If the timer has been canceled, abort_operation is sent. For example:
void handleTimer(const boost::system::error_code& error) { if (error == boost::asio::error::operation_aborted) { std::cout << "Timer was canceled" << std::endl; } else if (error) { std::cout << "Timer error: " << error.message() << std::endl; } }
Hope this helps. If not, what is the specific example you are looking for?
Yukiko
source share