basic_deadline_timer.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. //
  2. // basic_deadline_timer.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
  11. #define BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include <boost/asio/detail/deadline_timer_service.hpp>
  20. #include <boost/asio/detail/handler_type_requirements.hpp>
  21. #include <boost/asio/detail/io_object_impl.hpp>
  22. #include <boost/asio/detail/non_const_lvalue.hpp>
  23. #include <boost/asio/detail/throw_error.hpp>
  24. #include <boost/asio/error.hpp>
  25. #include <boost/asio/execution_context.hpp>
  26. #include <boost/asio/executor.hpp>
  27. #include <boost/asio/time_traits.hpp>
  28. #include <boost/asio/detail/push_options.hpp>
  29. namespace boost {
  30. namespace asio {
  31. /// Provides waitable timer functionality.
  32. /**
  33. * The basic_deadline_timer class template provides the ability to perform a
  34. * blocking or asynchronous wait for a timer to expire.
  35. *
  36. * A deadline timer is always in one of two states: "expired" or "not expired".
  37. * If the wait() or async_wait() function is called on an expired timer, the
  38. * wait operation will complete immediately.
  39. *
  40. * Most applications will use the boost::asio::deadline_timer typedef.
  41. *
  42. * @par Thread Safety
  43. * @e Distinct @e objects: Safe.@n
  44. * @e Shared @e objects: Unsafe.
  45. *
  46. * @par Examples
  47. * Performing a blocking wait:
  48. * @code
  49. * // Construct a timer without setting an expiry time.
  50. * boost::asio::deadline_timer timer(my_context);
  51. *
  52. * // Set an expiry time relative to now.
  53. * timer.expires_from_now(boost::posix_time::seconds(5));
  54. *
  55. * // Wait for the timer to expire.
  56. * timer.wait();
  57. * @endcode
  58. *
  59. * @par
  60. * Performing an asynchronous wait:
  61. * @code
  62. * void handler(const boost::system::error_code& error)
  63. * {
  64. * if (!error)
  65. * {
  66. * // Timer expired.
  67. * }
  68. * }
  69. *
  70. * ...
  71. *
  72. * // Construct a timer with an absolute expiry time.
  73. * boost::asio::deadline_timer timer(my_context,
  74. * boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
  75. *
  76. * // Start an asynchronous wait.
  77. * timer.async_wait(handler);
  78. * @endcode
  79. *
  80. * @par Changing an active deadline_timer's expiry time
  81. *
  82. * Changing the expiry time of a timer while there are pending asynchronous
  83. * waits causes those wait operations to be cancelled. To ensure that the action
  84. * associated with the timer is performed only once, use something like this:
  85. * used:
  86. *
  87. * @code
  88. * void on_some_event()
  89. * {
  90. * if (my_timer.expires_from_now(seconds(5)) > 0)
  91. * {
  92. * // We managed to cancel the timer. Start new asynchronous wait.
  93. * my_timer.async_wait(on_timeout);
  94. * }
  95. * else
  96. * {
  97. * // Too late, timer has already expired!
  98. * }
  99. * }
  100. *
  101. * void on_timeout(const boost::system::error_code& e)
  102. * {
  103. * if (e != boost::asio::error::operation_aborted)
  104. * {
  105. * // Timer was not cancelled, take necessary action.
  106. * }
  107. * }
  108. * @endcode
  109. *
  110. * @li The boost::asio::basic_deadline_timer::expires_from_now() function
  111. * cancels any pending asynchronous waits, and returns the number of
  112. * asynchronous waits that were cancelled. If it returns 0 then you were too
  113. * late and the wait handler has already been executed, or will soon be
  114. * executed. If it returns 1 then the wait handler was successfully cancelled.
  115. *
  116. * @li If a wait handler is cancelled, the boost::system::error_code passed to
  117. * it contains the value boost::asio::error::operation_aborted.
  118. */
  119. template <typename Time,
  120. typename TimeTraits = boost::asio::time_traits<Time>,
  121. typename Executor = executor>
  122. class basic_deadline_timer
  123. {
  124. public:
  125. /// The type of the executor associated with the object.
  126. typedef Executor executor_type;
  127. /// The time traits type.
  128. typedef TimeTraits traits_type;
  129. /// The time type.
  130. typedef typename traits_type::time_type time_type;
  131. /// The duration type.
  132. typedef typename traits_type::duration_type duration_type;
  133. /// Constructor.
  134. /**
  135. * This constructor creates a timer without setting an expiry time. The
  136. * expires_at() or expires_from_now() functions must be called to set an
  137. * expiry time before the timer can be waited on.
  138. *
  139. * @param ex The I/O executor that the timer will use, by default, to
  140. * dispatch handlers for any asynchronous operations performed on the timer.
  141. */
  142. explicit basic_deadline_timer(const executor_type& ex)
  143. : impl_(ex)
  144. {
  145. }
  146. /// Constructor.
  147. /**
  148. * This constructor creates a timer without setting an expiry time. The
  149. * expires_at() or expires_from_now() functions must be called to set an
  150. * expiry time before the timer can be waited on.
  151. *
  152. * @param context An execution context which provides the I/O executor that
  153. * the timer will use, by default, to dispatch handlers for any asynchronous
  154. * operations performed on the timer.
  155. */
  156. template <typename ExecutionContext>
  157. explicit basic_deadline_timer(ExecutionContext& context,
  158. typename enable_if<
  159. is_convertible<ExecutionContext&, execution_context&>::value
  160. >::type* = 0)
  161. : impl_(context)
  162. {
  163. }
  164. /// Constructor to set a particular expiry time as an absolute time.
  165. /**
  166. * This constructor creates a timer and sets the expiry time.
  167. *
  168. * @param ex The I/O executor that the timer will use, by default, to
  169. * dispatch handlers for any asynchronous operations performed on the timer.
  170. *
  171. * @param expiry_time The expiry time to be used for the timer, expressed
  172. * as an absolute time.
  173. */
  174. basic_deadline_timer(const executor_type& ex, const time_type& expiry_time)
  175. : impl_(ex)
  176. {
  177. boost::system::error_code ec;
  178. impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
  179. boost::asio::detail::throw_error(ec, "expires_at");
  180. }
  181. /// Constructor to set a particular expiry time as an absolute time.
  182. /**
  183. * This constructor creates a timer and sets the expiry time.
  184. *
  185. * @param context An execution context which provides the I/O executor that
  186. * the timer will use, by default, to dispatch handlers for any asynchronous
  187. * operations performed on the timer.
  188. *
  189. * @param expiry_time The expiry time to be used for the timer, expressed
  190. * as an absolute time.
  191. */
  192. template <typename ExecutionContext>
  193. basic_deadline_timer(ExecutionContext& context, const time_type& expiry_time,
  194. typename enable_if<
  195. is_convertible<ExecutionContext&, execution_context&>::value
  196. >::type* = 0)
  197. : impl_(context)
  198. {
  199. boost::system::error_code ec;
  200. impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec);
  201. boost::asio::detail::throw_error(ec, "expires_at");
  202. }
  203. /// Constructor to set a particular expiry time relative to now.
  204. /**
  205. * This constructor creates a timer and sets the expiry time.
  206. *
  207. * @param ex The I/O executor that the timer will use, by default, to
  208. * dispatch handlers for any asynchronous operations performed on the timer.
  209. *
  210. * @param expiry_time The expiry time to be used for the timer, relative to
  211. * now.
  212. */
  213. basic_deadline_timer(const executor_type& ex,
  214. const duration_type& expiry_time)
  215. : impl_(ex)
  216. {
  217. boost::system::error_code ec;
  218. impl_.get_service().expires_from_now(
  219. impl_.get_implementation(), expiry_time, ec);
  220. boost::asio::detail::throw_error(ec, "expires_from_now");
  221. }
  222. /// Constructor to set a particular expiry time relative to now.
  223. /**
  224. * This constructor creates a timer and sets the expiry time.
  225. *
  226. * @param context An execution context which provides the I/O executor that
  227. * the timer will use, by default, to dispatch handlers for any asynchronous
  228. * operations performed on the timer.
  229. *
  230. * @param expiry_time The expiry time to be used for the timer, relative to
  231. * now.
  232. */
  233. template <typename ExecutionContext>
  234. basic_deadline_timer(ExecutionContext& context,
  235. const duration_type& expiry_time,
  236. typename enable_if<
  237. is_convertible<ExecutionContext&, execution_context&>::value
  238. >::type* = 0)
  239. : impl_(context)
  240. {
  241. boost::system::error_code ec;
  242. impl_.get_service().expires_from_now(
  243. impl_.get_implementation(), expiry_time, ec);
  244. boost::asio::detail::throw_error(ec, "expires_from_now");
  245. }
  246. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  247. /// Move-construct a basic_deadline_timer from another.
  248. /**
  249. * This constructor moves a timer from one object to another.
  250. *
  251. * @param other The other basic_deadline_timer object from which the move will
  252. * occur.
  253. *
  254. * @note Following the move, the moved-from object is in the same state as if
  255. * constructed using the @c basic_deadline_timer(const executor_type&)
  256. * constructor.
  257. */
  258. basic_deadline_timer(basic_deadline_timer&& other)
  259. : impl_(std::move(other.impl_))
  260. {
  261. }
  262. /// Move-assign a basic_deadline_timer from another.
  263. /**
  264. * This assignment operator moves a timer from one object to another. Cancels
  265. * any outstanding asynchronous operations associated with the target object.
  266. *
  267. * @param other The other basic_deadline_timer object from which the move will
  268. * occur.
  269. *
  270. * @note Following the move, the moved-from object is in the same state as if
  271. * constructed using the @c basic_deadline_timer(const executor_type&)
  272. * constructor.
  273. */
  274. basic_deadline_timer& operator=(basic_deadline_timer&& other)
  275. {
  276. impl_ = std::move(other.impl_);
  277. return *this;
  278. }
  279. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  280. /// Destroys the timer.
  281. /**
  282. * This function destroys the timer, cancelling any outstanding asynchronous
  283. * wait operations associated with the timer as if by calling @c cancel.
  284. */
  285. ~basic_deadline_timer()
  286. {
  287. }
  288. /// Get the executor associated with the object.
  289. executor_type get_executor() BOOST_ASIO_NOEXCEPT
  290. {
  291. return impl_.get_executor();
  292. }
  293. /// Cancel any asynchronous operations that are waiting on the timer.
  294. /**
  295. * This function forces the completion of any pending asynchronous wait
  296. * operations against the timer. The handler for each cancelled operation will
  297. * be invoked with the boost::asio::error::operation_aborted error code.
  298. *
  299. * Cancelling the timer does not change the expiry time.
  300. *
  301. * @return The number of asynchronous operations that were cancelled.
  302. *
  303. * @throws boost::system::system_error Thrown on failure.
  304. *
  305. * @note If the timer has already expired when cancel() is called, then the
  306. * handlers for asynchronous wait operations will:
  307. *
  308. * @li have already been invoked; or
  309. *
  310. * @li have been queued for invocation in the near future.
  311. *
  312. * These handlers can no longer be cancelled, and therefore are passed an
  313. * error code that indicates the successful completion of the wait operation.
  314. */
  315. std::size_t cancel()
  316. {
  317. boost::system::error_code ec;
  318. std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec);
  319. boost::asio::detail::throw_error(ec, "cancel");
  320. return s;
  321. }
  322. /// Cancel any asynchronous operations that are waiting on the timer.
  323. /**
  324. * This function forces the completion of any pending asynchronous wait
  325. * operations against the timer. The handler for each cancelled operation will
  326. * be invoked with the boost::asio::error::operation_aborted error code.
  327. *
  328. * Cancelling the timer does not change the expiry time.
  329. *
  330. * @param ec Set to indicate what error occurred, if any.
  331. *
  332. * @return The number of asynchronous operations that were cancelled.
  333. *
  334. * @note If the timer has already expired when cancel() is called, then the
  335. * handlers for asynchronous wait operations will:
  336. *
  337. * @li have already been invoked; or
  338. *
  339. * @li have been queued for invocation in the near future.
  340. *
  341. * These handlers can no longer be cancelled, and therefore are passed an
  342. * error code that indicates the successful completion of the wait operation.
  343. */
  344. std::size_t cancel(boost::system::error_code& ec)
  345. {
  346. return impl_.get_service().cancel(impl_.get_implementation(), ec);
  347. }
  348. /// Cancels one asynchronous operation that is waiting on the timer.
  349. /**
  350. * This function forces the completion of one pending asynchronous wait
  351. * operation against the timer. Handlers are cancelled in FIFO order. The
  352. * handler for the cancelled operation will be invoked with the
  353. * boost::asio::error::operation_aborted error code.
  354. *
  355. * Cancelling the timer does not change the expiry time.
  356. *
  357. * @return The number of asynchronous operations that were cancelled. That is,
  358. * either 0 or 1.
  359. *
  360. * @throws boost::system::system_error Thrown on failure.
  361. *
  362. * @note If the timer has already expired when cancel_one() is called, then
  363. * the handlers for asynchronous wait operations will:
  364. *
  365. * @li have already been invoked; or
  366. *
  367. * @li have been queued for invocation in the near future.
  368. *
  369. * These handlers can no longer be cancelled, and therefore are passed an
  370. * error code that indicates the successful completion of the wait operation.
  371. */
  372. std::size_t cancel_one()
  373. {
  374. boost::system::error_code ec;
  375. std::size_t s = impl_.get_service().cancel_one(
  376. impl_.get_implementation(), ec);
  377. boost::asio::detail::throw_error(ec, "cancel_one");
  378. return s;
  379. }
  380. /// Cancels one asynchronous operation that is waiting on the timer.
  381. /**
  382. * This function forces the completion of one pending asynchronous wait
  383. * operation against the timer. Handlers are cancelled in FIFO order. The
  384. * handler for the cancelled operation will be invoked with the
  385. * boost::asio::error::operation_aborted error code.
  386. *
  387. * Cancelling the timer does not change the expiry time.
  388. *
  389. * @param ec Set to indicate what error occurred, if any.
  390. *
  391. * @return The number of asynchronous operations that were cancelled. That is,
  392. * either 0 or 1.
  393. *
  394. * @note If the timer has already expired when cancel_one() is called, then
  395. * the handlers for asynchronous wait operations will:
  396. *
  397. * @li have already been invoked; or
  398. *
  399. * @li have been queued for invocation in the near future.
  400. *
  401. * These handlers can no longer be cancelled, and therefore are passed an
  402. * error code that indicates the successful completion of the wait operation.
  403. */
  404. std::size_t cancel_one(boost::system::error_code& ec)
  405. {
  406. return impl_.get_service().cancel_one(impl_.get_implementation(), ec);
  407. }
  408. /// Get the timer's expiry time as an absolute time.
  409. /**
  410. * This function may be used to obtain the timer's current expiry time.
  411. * Whether the timer has expired or not does not affect this value.
  412. */
  413. time_type expires_at() const
  414. {
  415. return impl_.get_service().expires_at(impl_.get_implementation());
  416. }
  417. /// Set the timer's expiry time as an absolute time.
  418. /**
  419. * This function sets the expiry time. Any pending asynchronous wait
  420. * operations will be cancelled. The handler for each cancelled operation will
  421. * be invoked with the boost::asio::error::operation_aborted error code.
  422. *
  423. * @param expiry_time The expiry time to be used for the timer.
  424. *
  425. * @return The number of asynchronous operations that were cancelled.
  426. *
  427. * @throws boost::system::system_error Thrown on failure.
  428. *
  429. * @note If the timer has already expired when expires_at() is called, then
  430. * the handlers for asynchronous wait operations will:
  431. *
  432. * @li have already been invoked; or
  433. *
  434. * @li have been queued for invocation in the near future.
  435. *
  436. * These handlers can no longer be cancelled, and therefore are passed an
  437. * error code that indicates the successful completion of the wait operation.
  438. */
  439. std::size_t expires_at(const time_type& expiry_time)
  440. {
  441. boost::system::error_code ec;
  442. std::size_t s = impl_.get_service().expires_at(
  443. impl_.get_implementation(), expiry_time, ec);
  444. boost::asio::detail::throw_error(ec, "expires_at");
  445. return s;
  446. }
  447. /// Set the timer's expiry time as an absolute time.
  448. /**
  449. * This function sets the expiry time. Any pending asynchronous wait
  450. * operations will be cancelled. The handler for each cancelled operation will
  451. * be invoked with the boost::asio::error::operation_aborted error code.
  452. *
  453. * @param expiry_time The expiry time to be used for the timer.
  454. *
  455. * @param ec Set to indicate what error occurred, if any.
  456. *
  457. * @return The number of asynchronous operations that were cancelled.
  458. *
  459. * @note If the timer has already expired when expires_at() is called, then
  460. * the handlers for asynchronous wait operations will:
  461. *
  462. * @li have already been invoked; or
  463. *
  464. * @li have been queued for invocation in the near future.
  465. *
  466. * These handlers can no longer be cancelled, and therefore are passed an
  467. * error code that indicates the successful completion of the wait operation.
  468. */
  469. std::size_t expires_at(const time_type& expiry_time,
  470. boost::system::error_code& ec)
  471. {
  472. return impl_.get_service().expires_at(
  473. impl_.get_implementation(), expiry_time, ec);
  474. }
  475. /// Get the timer's expiry time relative to now.
  476. /**
  477. * This function may be used to obtain the timer's current expiry time.
  478. * Whether the timer has expired or not does not affect this value.
  479. */
  480. duration_type expires_from_now() const
  481. {
  482. return impl_.get_service().expires_from_now(impl_.get_implementation());
  483. }
  484. /// Set the timer's expiry time relative to now.
  485. /**
  486. * This function sets the expiry time. Any pending asynchronous wait
  487. * operations will be cancelled. The handler for each cancelled operation will
  488. * be invoked with the boost::asio::error::operation_aborted error code.
  489. *
  490. * @param expiry_time The expiry time to be used for the timer.
  491. *
  492. * @return The number of asynchronous operations that were cancelled.
  493. *
  494. * @throws boost::system::system_error Thrown on failure.
  495. *
  496. * @note If the timer has already expired when expires_from_now() is called,
  497. * then the handlers for asynchronous wait operations will:
  498. *
  499. * @li have already been invoked; or
  500. *
  501. * @li have been queued for invocation in the near future.
  502. *
  503. * These handlers can no longer be cancelled, and therefore are passed an
  504. * error code that indicates the successful completion of the wait operation.
  505. */
  506. std::size_t expires_from_now(const duration_type& expiry_time)
  507. {
  508. boost::system::error_code ec;
  509. std::size_t s = impl_.get_service().expires_from_now(
  510. impl_.get_implementation(), expiry_time, ec);
  511. boost::asio::detail::throw_error(ec, "expires_from_now");
  512. return s;
  513. }
  514. /// Set the timer's expiry time relative to now.
  515. /**
  516. * This function sets the expiry time. Any pending asynchronous wait
  517. * operations will be cancelled. The handler for each cancelled operation will
  518. * be invoked with the boost::asio::error::operation_aborted error code.
  519. *
  520. * @param expiry_time The expiry time to be used for the timer.
  521. *
  522. * @param ec Set to indicate what error occurred, if any.
  523. *
  524. * @return The number of asynchronous operations that were cancelled.
  525. *
  526. * @note If the timer has already expired when expires_from_now() is called,
  527. * then the handlers for asynchronous wait operations will:
  528. *
  529. * @li have already been invoked; or
  530. *
  531. * @li have been queued for invocation in the near future.
  532. *
  533. * These handlers can no longer be cancelled, and therefore are passed an
  534. * error code that indicates the successful completion of the wait operation.
  535. */
  536. std::size_t expires_from_now(const duration_type& expiry_time,
  537. boost::system::error_code& ec)
  538. {
  539. return impl_.get_service().expires_from_now(
  540. impl_.get_implementation(), expiry_time, ec);
  541. }
  542. /// Perform a blocking wait on the timer.
  543. /**
  544. * This function is used to wait for the timer to expire. This function
  545. * blocks and does not return until the timer has expired.
  546. *
  547. * @throws boost::system::system_error Thrown on failure.
  548. */
  549. void wait()
  550. {
  551. boost::system::error_code ec;
  552. impl_.get_service().wait(impl_.get_implementation(), ec);
  553. boost::asio::detail::throw_error(ec, "wait");
  554. }
  555. /// Perform a blocking wait on the timer.
  556. /**
  557. * This function is used to wait for the timer to expire. This function
  558. * blocks and does not return until the timer has expired.
  559. *
  560. * @param ec Set to indicate what error occurred, if any.
  561. */
  562. void wait(boost::system::error_code& ec)
  563. {
  564. impl_.get_service().wait(impl_.get_implementation(), ec);
  565. }
  566. /// Start an asynchronous wait on the timer.
  567. /**
  568. * This function may be used to initiate an asynchronous wait against the
  569. * timer. It always returns immediately.
  570. *
  571. * For each call to async_wait(), the supplied handler will be called exactly
  572. * once. The handler will be called when:
  573. *
  574. * @li The timer has expired.
  575. *
  576. * @li The timer was cancelled, in which case the handler is passed the error
  577. * code boost::asio::error::operation_aborted.
  578. *
  579. * @param handler The handler to be called when the timer expires. Copies
  580. * will be made of the handler as required. The function signature of the
  581. * handler must be:
  582. * @code void handler(
  583. * const boost::system::error_code& error // Result of operation.
  584. * ); @endcode
  585. * Regardless of whether the asynchronous operation completes immediately or
  586. * not, the handler will not be invoked from within this function. On
  587. * immediate completion, invocation of the handler will be performed in a
  588. * manner equivalent to using boost::asio::post().
  589. */
  590. template <typename WaitHandler>
  591. BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
  592. void (boost::system::error_code))
  593. async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  594. {
  595. return async_initiate<WaitHandler, void (boost::system::error_code)>(
  596. initiate_async_wait(), handler, this);
  597. }
  598. private:
  599. // Disallow copying and assignment.
  600. basic_deadline_timer(const basic_deadline_timer&) BOOST_ASIO_DELETED;
  601. basic_deadline_timer& operator=(
  602. const basic_deadline_timer&) BOOST_ASIO_DELETED;
  603. struct initiate_async_wait
  604. {
  605. template <typename WaitHandler>
  606. void operator()(BOOST_ASIO_MOVE_ARG(WaitHandler) handler,
  607. basic_deadline_timer* self) const
  608. {
  609. // If you get an error on the following line it means that your handler
  610. // does not meet the documented type requirements for a WaitHandler.
  611. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
  612. detail::non_const_lvalue<WaitHandler> handler2(handler);
  613. self->impl_.get_service().async_wait(
  614. self->impl_.get_implementation(), handler2.value,
  615. self->impl_.get_implementation_executor());
  616. }
  617. };
  618. detail::io_object_impl<
  619. detail::deadline_timer_service<TimeTraits>, Executor> impl_;
  620. };
  621. } // namespace asio
  622. } // namespace boost
  623. #include <boost/asio/detail/pop_options.hpp>
  624. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  625. // || defined(GENERATING_DOCUMENTATION)
  626. #endif // BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP