asio C++ library

PrevUpHomeNext

experimental::use_coro_t

A completion token that creates another coro for the task completion.

template<
    typename Allocator = std::allocator<void>>
struct use_coro_t
Types

Name

Description

allocator_type

The allocator type. The allocator is used when constructing the std::promise object for a given asynchronous operation.

as_default_on_t

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

executor_with_default

Adapts an executor to add the use_coro_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_coro_t as its default completion token type.

get_allocator

Obtain allocator.

rebind

Specify an alternate allocator.

use_coro_t [constructor]

Default constructor.

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

The use_coro_t class, with its value use_coro, is used to represent an operation that can be awaited by the current resumable coroutine. This completion token may be passed as a handler to an asynchronous operation. For example:

coro<void> my_coroutine(tcp::socket my_socket)
{
  std::size_t n = co_await my_socket.async_read_some(buffer, use_coro);
  ...
}

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.

Note that this token is not the most efficient (use asio::deferred for that) but does provide type erasure, as it will always return a coro.

Requirements

Header: asio/experimental/use_coro.hpp

Convenience header: None


PrevUpHomeNext