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

yield_context

A completion token object that represents the currently executing coroutine.

typedef basic_yield_context< any_io_executor > yield_context;
Types

Name

Description

cancellation_slot_type

The cancellation slot type associated with the yield context.

executor_type

The executor type associated with the yield context.

Member Functions

Name

Description

basic_yield_context [constructor]

Construct a yield context from another yield context type.

cancelled

Determine whether the current coroutine has been cancelled.

get_cancellation_slot

Get the cancellation slot associated with the coroutine.

get_cancellation_state

Get the cancellation state associated with the coroutine.

get_executor

Get the executor associated with the yield context.

operator[]

Return a yield context that sets the specified error_code.

reset_cancellation_state

Reset the cancellation state associated with the coroutine.

throw_if_cancelled

Determine whether the coroutine throws if trying to suspend when it has been cancelled.

Set whether the coroutine throws if trying to suspend when it has been cancelled.

The basic_yield_context class is a completion token type that is used to represent the currently executing stackful coroutine. A basic_yield_context object may be passed as a completion token to an asynchronous operation. For example:

template <typename Executor>
void my_coroutine(basic_yield_context<Executor> yield)
{
  ...
  std::size_t n = my_socket.async_read_some(buffer, yield);
  ...
}

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/spawn.hpp

Convenience header: None


PrevUpHomeNext