Hello I have an interval timer and I would like it to terminate without waiting for it's interval to terminate. How should I do this? I have tried controlling the function with a reading flag. Once the reading flag is set to stop, I would like the function to exit without waiting for one iteration of the interval timer in order to exit.
void send_poll()
{
// Schedule the timer for the first time:
timer.async_wait(poll_device);
// Enter IO loop. The timer will fire for the first time 1 second from now:
io_service.run();
}
void poll_device(const boost::system::error_code& /*e*/)
{
std:: cout << "message being polled" << std::endl;
// do polling of device
if (reading_flag!=1)
{
std::terminate();
}
// Reschedule the timer for 1 second in the future:
timer.expires_at(timer.expires_at() + interval);
// Posts the timer event
timer.async_wait(poll_device)
}