title: Trouble implementing generic Timer Class using boost::asio::deadline_timer
body: <p>Implementing a timer class on a UI application.</p>
  
  <p>Basically the problem I have is that calling <code>io.run()</code> would block, rendering the <code>async_wait</code> call useless. From reading other posts I got the impression that somehow Timer, or at least the code that calls <code>startCountdown</code>, should be on another thread. </p>
  
  <p>Below is my code. How do I manage this in a way that is considered correct in Boost?</p>
  
  <pre><code>class Timer
  {
  public:
  
      Timer() : countdownTimer(io) {  }
  
      void startCountdown(int seconds)
      {
          countdownTimer.expires_from_now(boost::posix_time::seconds(seconds));
          countdownTimer.async_wait(boost::bind(&amp;Timer::on_timeout, this, _1));
          io.run(); // this blocks
      }
  
      void on_timeout(const boost::system::error_code&amp; e)
      {
          if (e != boost::asio::error::operation_aborted) {
              cout &lt;&lt; "Timer expired!";
          }
      }
  
  private:
  
      boost::asio::io_service io;
      boost::asio::deadline_timer countdownTimer;
  }
  </code></pre>