1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>use_awaitable_t</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="../reference.html" title="Reference"> 9<link rel="prev" href="use_awaitable.html" title="use_awaitable"> 10<link rel="next" href="use_awaitable_t/as_default_on.html" title="use_awaitable_t::as_default_on"> 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="use_awaitable.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="use_awaitable_t/as_default_on.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.reference.use_awaitable_t"></a><a class="link" href="use_awaitable_t.html" title="use_awaitable_t">use_awaitable_t</a> 28</h3></div></div></div> 29<p> 30 A completion token that represents the currently executing coroutine. 31 </p> 32<pre class="programlisting">template< 33 typename <a class="link" href="Executor1.html" title="Executor requirements">Executor</a> = any_io_executor> 34struct use_awaitable_t 35</pre> 36<h5> 37<a name="boost_asio.reference.use_awaitable_t.h0"></a> 38 <span class="phrase"><a name="boost_asio.reference.use_awaitable_t.types"></a></span><a class="link" href="use_awaitable_t.html#boost_asio.reference.use_awaitable_t.types">Types</a> 39 </h5> 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><tr> 58<td> 59 <p> 60 <a class="link" href="use_awaitable_t__executor_with_default.html" title="use_awaitable_t::executor_with_default"><span class="bold"><strong>executor_with_default</strong></span></a> 61 </p> 62 </td> 63<td> 64 <p> 65 Adapts an executor to add the use_awaitable_t completion token 66 as the default. 67 </p> 68 </td> 69</tr></tbody> 70</table></div> 71<h5> 72<a name="boost_asio.reference.use_awaitable_t.h1"></a> 73 <span class="phrase"><a name="boost_asio.reference.use_awaitable_t.member_functions"></a></span><a class="link" href="use_awaitable_t.html#boost_asio.reference.use_awaitable_t.member_functions">Member Functions</a> 74 </h5> 75<div class="informaltable"><table class="table"> 76<colgroup> 77<col> 78<col> 79</colgroup> 80<thead><tr> 81<th> 82 <p> 83 Name 84 </p> 85 </th> 86<th> 87 <p> 88 Description 89 </p> 90 </th> 91</tr></thead> 92<tbody> 93<tr> 94<td> 95 <p> 96 <a class="link" href="use_awaitable_t/as_default_on.html" title="use_awaitable_t::as_default_on"><span class="bold"><strong>as_default_on</strong></span></a> <span class="silver">[static]</span> 97 </p> 98 </td> 99<td> 100 <p> 101 Function helper to adapt an I/O object to use use_awaitable_t as 102 its default completion token type. 103 </p> 104 </td> 105</tr> 106<tr> 107<td> 108 <p> 109 <a class="link" href="use_awaitable_t/use_awaitable_t.html" title="use_awaitable_t::use_awaitable_t"><span class="bold"><strong>use_awaitable_t</strong></span></a> <span class="silver">[constructor]</span> 110 </p> 111 </td> 112<td> 113 <p> 114 Default constructor. <br> <span class="silver"> —</span><br> Constructor used to specify 115 file name, line, and function name. 116 </p> 117 </td> 118</tr> 119</tbody> 120</table></div> 121<p> 122 The <code class="computeroutput">use_awaitable_t</code> class, with its value <code class="computeroutput">use_awaitable</code>, 123 is used to represent the currently executing coroutine. This completion token 124 may be passed as a handler to an asynchronous operation. For example: 125 </p> 126<pre class="programlisting">awaitable<void> my_coroutine() 127{ 128 std::size_t n = co_await my_socket.async_read_some(buffer, use_awaitable); 129 ... 130} 131</pre> 132<p> 133 When used with co_await, the initiating function (<code class="computeroutput">async_read_some</code> 134 in the above example) suspends the current coroutine. The coroutine is resumed 135 when the asynchronous operation completes, and the result of the operation 136 is returned. 137 </p> 138<h5> 139<a name="boost_asio.reference.use_awaitable_t.h2"></a> 140 <span class="phrase"><a name="boost_asio.reference.use_awaitable_t.requirements"></a></span><a class="link" href="use_awaitable_t.html#boost_asio.reference.use_awaitable_t.requirements">Requirements</a> 141 </h5> 142<p> 143 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/use_awaitable.hpp</code> 144 </p> 145<p> 146 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code> 147 </p> 148</div> 149<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 150<td align="left"></td> 151<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 152 Kohlhoff<p> 153 Distributed under the Boost Software License, Version 1.0. (See accompanying 154 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>) 155 </p> 156</div></td> 157</tr></table> 158<hr> 159<div class="spirit-nav"> 160<a accesskey="p" href="use_awaitable.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="use_awaitable_t/as_default_on.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 161</div> 162</body> 163</html> 164