1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>basic_deadline_timer::rebind_executor::other</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../basic_deadline_timer__rebind_executor.html" title="basic_deadline_timer::rebind_executor"> 9<link rel="prev" href="../basic_deadline_timer__rebind_executor.html" title="basic_deadline_timer::rebind_executor"> 10<link rel="next" href="../basic_io_object.html" title="basic_io_object"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../basic_deadline_timer__rebind_executor.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../basic_deadline_timer__rebind_executor.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../basic_io_object.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other"></a><a class="link" href="other.html" title="basic_deadline_timer::rebind_executor::other">basic_deadline_timer::rebind_executor::other</a> 28</h4></div></div></div> 29<p> 30 <a class="indexterm" name="boost_asio.indexterm.basic_deadline_timer__rebind_executor.other"></a> 31The 32 timer type when rebound to the specified executor. 33 </p> 34<pre class="programlisting">typedef basic_deadline_timer< Time, TimeTraits, Executor1 > other; 35</pre> 36<h6> 37<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h0"></a> 38 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.types"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.types">Types</a> 39 </h6> 40<div class="informaltable"><table class="table"> 41<colgroup> 42<col> 43<col> 44</colgroup> 45<thead><tr> 46<th> 47 <p> 48 Name 49 </p> 50 </th> 51<th> 52 <p> 53 Description 54 </p> 55 </th> 56</tr></thead> 57<tbody> 58<tr> 59<td> 60 <p> 61 <a class="link" href="../basic_deadline_timer__rebind_executor.html" title="basic_deadline_timer::rebind_executor"><span class="bold"><strong>rebind_executor</strong></span></a> 62 </p> 63 </td> 64<td> 65 <p> 66 Rebinds the timer type to another executor. 67 </p> 68 </td> 69</tr> 70<tr> 71<td> 72 <p> 73 <a class="link" href="../basic_deadline_timer/duration_type.html" title="basic_deadline_timer::duration_type"><span class="bold"><strong>duration_type</strong></span></a> 74 </p> 75 </td> 76<td> 77 <p> 78 The duration type. 79 </p> 80 </td> 81</tr> 82<tr> 83<td> 84 <p> 85 <a class="link" href="../basic_deadline_timer/executor_type.html" title="basic_deadline_timer::executor_type"><span class="bold"><strong>executor_type</strong></span></a> 86 </p> 87 </td> 88<td> 89 <p> 90 The type of the executor associated with the object. 91 </p> 92 </td> 93</tr> 94<tr> 95<td> 96 <p> 97 <a class="link" href="../basic_deadline_timer/time_type.html" title="basic_deadline_timer::time_type"><span class="bold"><strong>time_type</strong></span></a> 98 </p> 99 </td> 100<td> 101 <p> 102 The time type. 103 </p> 104 </td> 105</tr> 106<tr> 107<td> 108 <p> 109 <a class="link" href="../basic_deadline_timer/traits_type.html" title="basic_deadline_timer::traits_type"><span class="bold"><strong>traits_type</strong></span></a> 110 </p> 111 </td> 112<td> 113 <p> 114 The time traits type. 115 </p> 116 </td> 117</tr> 118</tbody> 119</table></div> 120<h6> 121<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h1"></a> 122 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.member_functions"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.member_functions">Member 123 Functions</a> 124 </h6> 125<div class="informaltable"><table class="table"> 126<colgroup> 127<col> 128<col> 129</colgroup> 130<thead><tr> 131<th> 132 <p> 133 Name 134 </p> 135 </th> 136<th> 137 <p> 138 Description 139 </p> 140 </th> 141</tr></thead> 142<tbody> 143<tr> 144<td> 145 <p> 146 <a class="link" href="../basic_deadline_timer/async_wait.html" title="basic_deadline_timer::async_wait"><span class="bold"><strong>async_wait</strong></span></a> 147 </p> 148 </td> 149<td> 150 <p> 151 Start an asynchronous wait on the timer. 152 </p> 153 </td> 154</tr> 155<tr> 156<td> 157 <p> 158 <a class="link" href="../basic_deadline_timer/basic_deadline_timer.html" title="basic_deadline_timer::basic_deadline_timer"><span class="bold"><strong>basic_deadline_timer</strong></span></a> <span class="silver">[constructor]</span> 159 </p> 160 </td> 161<td> 162 <p> 163 Constructor. <br> <span class="silver"> —</span><br> Constructor to set a particular expiry 164 time as an absolute time. <br> <span class="silver"> —</span><br> Constructor to set a 165 particular expiry time relative to now. <br> <span class="silver"> —</span><br> Move-construct 166 a basic_deadline_timer from another. 167 </p> 168 </td> 169</tr> 170<tr> 171<td> 172 <p> 173 <a class="link" href="../basic_deadline_timer/cancel.html" title="basic_deadline_timer::cancel"><span class="bold"><strong>cancel</strong></span></a> 174 </p> 175 </td> 176<td> 177 <p> 178 Cancel any asynchronous operations that are waiting on the timer. 179 </p> 180 </td> 181</tr> 182<tr> 183<td> 184 <p> 185 <a class="link" href="../basic_deadline_timer/cancel_one.html" title="basic_deadline_timer::cancel_one"><span class="bold"><strong>cancel_one</strong></span></a> 186 </p> 187 </td> 188<td> 189 <p> 190 Cancels one asynchronous operation that is waiting on the timer. 191 </p> 192 </td> 193</tr> 194<tr> 195<td> 196 <p> 197 <a class="link" href="../basic_deadline_timer/expires_at.html" title="basic_deadline_timer::expires_at"><span class="bold"><strong>expires_at</strong></span></a> 198 </p> 199 </td> 200<td> 201 <p> 202 Get the timer's expiry time as an absolute time. <br> <span class="silver"> —</span><br> 203 Set the timer's expiry time as an absolute time. 204 </p> 205 </td> 206</tr> 207<tr> 208<td> 209 <p> 210 <a class="link" href="../basic_deadline_timer/expires_from_now.html" title="basic_deadline_timer::expires_from_now"><span class="bold"><strong>expires_from_now</strong></span></a> 211 </p> 212 </td> 213<td> 214 <p> 215 Get the timer's expiry time relative to now. <br> <span class="silver"> —</span><br> Set 216 the timer's expiry time relative to now. 217 </p> 218 </td> 219</tr> 220<tr> 221<td> 222 <p> 223 <a class="link" href="../basic_deadline_timer/get_executor.html" title="basic_deadline_timer::get_executor"><span class="bold"><strong>get_executor</strong></span></a> 224 </p> 225 </td> 226<td> 227 <p> 228 Get the executor associated with the object. 229 </p> 230 </td> 231</tr> 232<tr> 233<td> 234 <p> 235 <a class="link" href="../basic_deadline_timer/operator_eq_.html" title="basic_deadline_timer::operator="><span class="bold"><strong>operator=</strong></span></a> 236 </p> 237 </td> 238<td> 239 <p> 240 Move-assign a basic_deadline_timer from another. 241 </p> 242 </td> 243</tr> 244<tr> 245<td> 246 <p> 247 <a class="link" href="../basic_deadline_timer/wait.html" title="basic_deadline_timer::wait"><span class="bold"><strong>wait</strong></span></a> 248 </p> 249 </td> 250<td> 251 <p> 252 Perform a blocking wait on the timer. 253 </p> 254 </td> 255</tr> 256<tr> 257<td> 258 <p> 259 <a class="link" href="../basic_deadline_timer/_basic_deadline_timer.html" title="basic_deadline_timer::~basic_deadline_timer"><span class="bold"><strong>~basic_deadline_timer</strong></span></a> <span class="silver">[destructor]</span> 260 </p> 261 </td> 262<td> 263 <p> 264 Destroys the timer. 265 </p> 266 </td> 267</tr> 268</tbody> 269</table></div> 270<p> 271 The <a class="link" href="../basic_deadline_timer.html" title="basic_deadline_timer"><code class="computeroutput">basic_deadline_timer</code></a> 272 class template provides the ability to perform a blocking or asynchronous 273 wait for a timer to expire. 274 </p> 275<p> 276 A deadline timer is always in one of two states: "expired" or 277 "not expired". If the <code class="computeroutput">wait()</code> or <code class="computeroutput">async_wait()</code> 278 function is called on an expired timer, the wait operation will complete 279 immediately. 280 </p> 281<p> 282 Most applications will use the <a class="link" href="../deadline_timer.html" title="deadline_timer"><code class="computeroutput">deadline_timer</code></a> 283 typedef. 284 </p> 285<h6> 286<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h2"></a> 287 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.thread_safety"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.thread_safety">Thread 288 Safety</a> 289 </h6> 290<p> 291 <span class="emphasis"><em>Distinct</em></span> <span class="emphasis"><em>objects:</em></span> Safe. 292 </p> 293<p> 294 <span class="emphasis"><em>Shared</em></span> <span class="emphasis"><em>objects:</em></span> Unsafe. 295 </p> 296<h6> 297<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h3"></a> 298 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.examples"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.examples">Examples</a> 299 </h6> 300<p> 301 Performing a blocking wait: 302 </p> 303<pre class="programlisting">// Construct a timer without setting an expiry time. 304boost::asio::deadline_timer timer(my_context); 305 306// Set an expiry time relative to now. 307timer.expires_from_now(boost::posix_time::seconds(5)); 308 309// Wait for the timer to expire. 310timer.wait(); 311</pre> 312<p> 313 Performing an asynchronous wait: 314 </p> 315<pre class="programlisting">void handler(const boost::system::error_code& error) 316{ 317 if (!error) 318 { 319 // Timer expired. 320 } 321} 322 323... 324 325// Construct a timer with an absolute expiry time. 326boost::asio::deadline_timer timer(my_context, 327 boost::posix_time::time_from_string("2005-12-07 23:59:59.000")); 328 329// Start an asynchronous wait. 330timer.async_wait(handler); 331</pre> 332<h6> 333<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h4"></a> 334 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.changing_an_active_deadline_timer_s_expiry_time"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.changing_an_active_deadline_timer_s_expiry_time">Changing 335 an active deadline_timer's expiry time</a> 336 </h6> 337<p> 338 Changing the expiry time of a timer while there are pending asynchronous 339 waits causes those wait operations to be cancelled. To ensure that the 340 action associated with the timer is performed only once, use something 341 like this: used: 342 </p> 343<pre class="programlisting">void on_some_event() 344{ 345 if (my_timer.expires_from_now(seconds(5)) > 0) 346 { 347 // We managed to cancel the timer. Start new asynchronous wait. 348 my_timer.async_wait(on_timeout); 349 } 350 else 351 { 352 // Too late, timer has already expired! 353 } 354} 355 356void on_timeout(const boost::system::error_code& e) 357{ 358 if (e != boost::asio::error::operation_aborted) 359 { 360 // Timer was not cancelled, take necessary action. 361 } 362} 363</pre> 364<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 365<li class="listitem"> 366 The <code class="computeroutput">boost::asio::basic_deadline_timer::expires_from_now()</code> 367 function cancels any pending asynchronous waits, and returns the number 368 of asynchronous waits that were cancelled. If it returns 0 then you 369 were too late and the wait handler has already been executed, or will 370 soon be executed. If it returns 1 then the wait handler was successfully 371 cancelled. 372 </li> 373<li class="listitem"> 374 If a wait handler is cancelled, the boost::system::error_code passed 375 to it contains the value <code class="computeroutput">boost::asio::error::operation_aborted</code>. 376 </li> 377</ul></div> 378<h6> 379<a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.h5"></a> 380 <span class="phrase"><a name="boost_asio.reference.basic_deadline_timer__rebind_executor.other.requirements"></a></span><a class="link" href="other.html#boost_asio.reference.basic_deadline_timer__rebind_executor.other.requirements">Requirements</a> 381 </h6> 382<p> 383 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/basic_deadline_timer.hpp</code> 384 </p> 385<p> 386 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code> 387 </p> 388</div> 389<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 390<td align="left"></td> 391<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 392 Kohlhoff<p> 393 Distributed under the Boost Software License, Version 1.0. (See accompanying 394 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 395 </p> 396</div></td> 397</tr></table> 398<hr> 399<div class="spirit-nav"> 400<a accesskey="p" href="../basic_deadline_timer__rebind_executor.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../basic_deadline_timer__rebind_executor.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../basic_io_object.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 401</div> 402</body> 403</html> 404