Boost Asio总结(10)定时器

template <typename Clock, typename WaitTraits, typename Executor>
class basic_waitable_timer
{
    
    
public:
  /// The type of the executor associated with the object.
  typedef Executor executor_type;

  /// The clock type.
  typedef Clock clock_type;

  /// The duration type of the clock.
  typedef typename clock_type::duration duration;

  /// The time point type of the clock.
  typedef typename clock_type::time_point time_point;

  std::size_t cancel()
  {
    
    
    boost::system::error_code ec;
    std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
    boost::asio::detail::throw_error(ec, "cancel");
    return s;
  }

  time_point expires_at() const
  {
    
    
    return impl_.get_service().expires_at(impl_.get_implementation());
  }

  time_point expiry() const
  {
    
    
    return impl_.get_service().expiry(impl_.get_implementation());
  }

  std::size_t expires_after(const duration& expiry_time)
  {
    
    
    boost::system::error_code ec;
    std::size_t s = impl_.get_service().expires_after(
        impl_.get_implementation(), expiry_time, ec);
    boost::asio::detail::throw_error(ec, "expires_after");
    return s;
  }

  void wait()
  {
    
    
    boost::system::error_code ec;
    impl_.get_service().wait(impl_.get_implementation(), ec);
    boost::asio::detail::throw_error(ec, "wait");
  }

  template <typename WaitHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
      void (boost::system::error_code))
  async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  {
    
    
    return async_initiate<WaitHandler, void (boost::system::error_code)>(
        initiate_async_wait(), handler, this);
  }


猜你喜欢

转载自blog.csdn.net/thefist11cc/article/details/123565432