Reputation: 593
Should the timer object exist until the task is completed?
I mean the following:
boost::asio::io_service io;
{
boost::asio::steady_timer timer(io, std::chrono::seconds(5));
timer.async_wait(someCallback);
} // the timer object is deleted here
io.run();
Is this allowed and does it lead to undefined behavior?
Upvotes: 0
Views: 262
Reputation: 36479
The destructor simply cancels any pending waits so your callback will be called with the boost::asio::error::operation_aborted
error code.
Upvotes: 2