int main() { boost::asio::io_service io_service; boost::asio::deadline_timer timer(io_service); timer.expires_from_now(boost::posix_time::seconds(5)); timer.async_wait([](const boost::system::error_code& err) { std::cout << (err ? "error" : "okay") ;});
If you use io_service.poll_one(); , you most likely will not see any output, because the timer has not passed yet. ready handler simply means a handle that is ready to start (for example, after a timer expires or the operation completes, etc.). However, if you use io_service.run_one(); , this call will be blocked until the timer finishes and the handler executes.
source share