Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

use_awaitable_t

A completion token that represents the currently executing coroutine.

template<
    typename Executor = any_io_executor>
struct use_awaitable_t
Types

Name

Description

as_default_on_t

Type alias to adapt an I/O object to use use_awaitable_t as its default completion token type.

executor_with_default

Adapts an executor to add the use_awaitable_t completion token as the default.

Member Functions

Name

Description

as_default_on [static]

Function helper to adapt an I/O object to use use_awaitable_t as its default completion token type.

use_awaitable_t [constructor]

Default constructor.

Constructor used to specify file name, line, and function name.

The use_awaitable_t class, with its value use_awaitable, is used to represent the currently executing coroutine. This completion token may be passed as a handler to an asynchronous operation. For example:

awaitable<void> my_coroutine()
{
  std::size_t n = co_await my_socket.async_read_some(buffer, use_awaitable);
  ...
}

When used with co_await, the initiating function (async_read_some in the above example) suspends the current coroutine. The coroutine is resumed when the asynchronous operation completes, and the result of the operation is returned.

Requirements

Header: boost/asio/use_awaitable.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext