Skip to content

Commit

Permalink
Add experimental::as_single completion token adapter.
Browse files Browse the repository at this point in the history
The as_single completion token adapter can be used to specify that the
completion handler arguments should be combined into a single argument.
For completion signatures with a single parameter, the argument is
passed through as-is. For signatures with two or more parameters, the
arguments are combined into a tuple.

The as_single adapter may be used in conjunction with use_awaitable and
structured bindings as follows:

    auto [e, n] = co_await socket.async_read_some(
        boost::asio::buffer(data), as_single(use_awaitable));

Alternatively, it may be used as a default completion token like so:

    using default_token = as_single_t<use_awaitable_t<>>;
    using tcp_socket = default_token::as_default_on_t<tcp::socket>;
    // ...
    awaitable<void> do_read(tcp_socket socket)
    {
      // ...
      auto [e, n] = co_await socket.async_read_some(boost::asio::buffer(data));
      // ...
    }
  • Loading branch information
chriskohlhoff committed Nov 2, 2020
1 parent c034e39 commit 311d355
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/quickref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
<member><link linkend="boost_asio.reference.basic_yield_context">basic_yield_context</link></member>
<member><link linkend="boost_asio.reference.executor_binder">executor_binder</link></member>
<member><link linkend="boost_asio.reference.executor_work_guard">executor_work_guard</link></member>
<member><link linkend="boost_asio.reference.experimental__as_single_t">experimental::as_single_t</link></member>
<member><link linkend="boost_asio.reference.io_context__basic_executor_type">io_context::basic_executor_type</link></member>
<member><link linkend="boost_asio.reference.redirect_error_t">redirect_error_t</link></member>
<member><link linkend="boost_asio.reference.strand">strand</link></member>
Expand All @@ -261,6 +262,7 @@
<simplelist type="vert" columns="1">
<member><link linkend="boost_asio.reference.detached">detached</link></member>
<member><link linkend="boost_asio.reference.executor_arg">executor_arg</link></member>
<member><link linkend="boost_asio.reference.experimental__as_single">experimental::as_single</link></member>
<member><link linkend="boost_asio.reference.this_coro__executor">this_coro::executor</link></member>
<member><link linkend="boost_asio.reference.use_future">use_future</link></member>
<member><link linkend="boost_asio.reference.use_awaitable">use_awaitable</link></member>
Expand Down
1 change: 1 addition & 0 deletions doc/reference.dox
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ INPUT = ./../../../boost/asio.hpp \
./../../../boost/asio/ssl \
./../../../boost/asio/windows \
./../../../boost/asio/execution \
./../../../boost/asio/experimental \
./noncopyable_dox.txt \
./std_exception_dox.txt
FILE_PATTERNS =
Expand Down
Loading

0 comments on commit 311d355

Please sign in to comment.