Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] How do you fake the time for boost timers?
From: Josh (0zeroth_at_[hidden])
Date: 2013-01-14 17:40:23


Josh Quigley <0zeroth <at> gmail.com> writes:

Apologies about the formatting snafu. The code should have read:

 
For example, is it possible to achieve something like the following:

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

void print(const boost::system::error_code& /*e*/)
{
  std::cout << "Hello, world!\n";
}

int main()
{
    boost::asio::io_service io; // Possibly another class needed here, or
a way of setting the clock to be fake

    boost::asio::deadline_timer t(io, boost::posix_time::hours(24));
    t.async_wait(&print);

    io.poll(); // Nothing should happen - no handlers ready

    // PSEUDO-CODE below of what I'd like to happen, jump ahead 24 hours
    io.set_time(io.get_time() + boost::posix_time::hours(24));

    io.poll(); // The timer should go off

    return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net