title: Boost.Asio: What's the Behavior of a deadline_timer with 0 Millisecond Expiration
body: <p>What the behavior of a <code>deadline_timer</code> whose expiration is 0 milliseconds?</p>
  
  <p>In my code, I have:</p>
  
  <pre><code>boost::asio::io_service ios;
  ...
  boost::asio::deadline_timer ptimer(ios);
  ptimer.expires_from_now(boost::posix_time::milliseconds(duration)); // Duration might be 0 sometimes
  boost::system::error_code ec;
  ptimer.async_wait(boost::bind(&amp;SomeTimeOutHandler, this, ec));
  </code></pre>
  
  <p>I found that if <code>duration == 0</code>, the handler <code>SomeTimeOutHandler</code> never gets called.</p>
  
  <p>I want it gets called.</p>
  
  <p>However, if I change to <code>duration == 1</code>, the handler does get called.</p>
  
  <p>So what the exact behavior it should be when the <code>deadline_timer</code>'s expiration is 0?</p>
  
  <p><em><strong>Edit:</em></strong></p>
  
  <p>But the following HelloWorld test program is working (suggested by @Roger):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  
  void SomeTimeOutHandler(const boost::system::error_code&amp; ec)
  {
      if (ec)
      {
          std::cout &lt;&lt; "SomeTimeOutHandler error_code" &lt;&lt; std::endl;
      }
      else
      {
          std::cout &lt;&lt; "I'm in good shape" &lt;&lt; std::endl;
      }
  }
  
  void Test(int duration)
  {
      boost::asio::io_service ios;
      boost::asio::deadline_timer ptimer(ios);
  
      ptimer.expires_from_now(boost::posix_time::milliseconds(duration));
      boost::system::error_code ec;
  
      ptimer.async_wait(boost::bind(&amp;SomeTimeOutHandler, ec));
  
      ios.run();
  
  //    boost::this_thread::sleep(boost::posix_time::milliseconds(duration * 2 + 1000));
  }
  
  
  int main(int argc, char* argv[])
  {
      Test(10); // Test(0);
  
      return 0;
  }
  </code></pre>