Hi,

below is some code where
    boost::asio::io_service::work
is added, and then immediately removed.

After that, I call async_wait on a steady_timer, but it does not work:
io.run() RETURNS IMMEDIATELY, and IGNORES the async_wait.

Is this intended?
(I was rather surprised, because I thought that the async_wait would schedule new work, but it does not work).

If I cange the code-line
    #define WEIRD_BEHAVIOUR
to
    #undef WEIRD_BEHAVIOUR
then I have my expected behaviour.

Thanks,
ajneu



#include <iostream>
#include <chrono>
#include <experimental/optional>

#include <boost/asio.hpp>
#include <boost/asio/steady_timer.hpp>


#define WEIRD_BEHAVIOUR

int main()
{
    boost::asio::io_service io;
    std::experimental::optional<boost::asio::io_service::work> work;

#ifdef WEIRD_BEHAVIOUR
    work.emplace(io);
    work = std::experimental::nullopt;
#endif

    boost::asio::steady_timer timer(io, std::chrono::milliseconds{1000});

    timer.async_wait([](const boost::system::error_code &ec) {
            std::cout << ((!ec) ? "done" : "err") << std::endl;
        });

    io.run();
}