Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::asio::basic_yield_context< Handler > Class Template Reference

Context object the represents the currently executing coroutine. More...

#include <spawn.hpp>

Collaboration diagram for boost::asio::basic_yield_context< Handler >:

Public Types

typedef
boost::coroutines::coroutine
< void()> 
callee_type
 The coroutine callee type, used by the implementation. More...
 
typedef
boost::coroutines::coroutine
< void()>::caller_type 
caller_type
 The coroutine caller type, used by the implementation. More...
 

Public Member Functions

 basic_yield_context (const detail::weak_ptr< callee_type > &coro, caller_type &ca, Handler &handler)
 Construct a yield context to represent the specified coroutine. More...
 
basic_yield_context operator[] (boost::system::error_code &ec) const
 Return a yield context that sets the specified error_code. More...
 

Public Attributes

detail::weak_ptr< callee_typecoro_
 
caller_typeca_
 
Handler & handler_
 
boost::system::error_codeec_
 

Detailed Description

template<typename Handler>
class boost::asio::basic_yield_context< Handler >

Context object the represents the currently executing coroutine.

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

template <typename Handler>
void my_coroutine(basic_yield_context<Handler> 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.

Member Typedef Documentation

template<typename Handler>
typedef boost::coroutines::coroutine<void()> boost::asio::basic_yield_context< Handler >::callee_type

The coroutine callee type, used by the implementation.

When using Boost.Coroutine v1, this type is:

typename coroutine<void()>

When using Boost.Coroutine v2 (unidirectional coroutines), this type is:

push_coroutine<void>
template<typename Handler>
typedef boost::coroutines::coroutine<void()>::caller_type boost::asio::basic_yield_context< Handler >::caller_type

The coroutine caller type, used by the implementation.

When using Boost.Coroutine v1, this type is:

typename coroutine<void()>::caller_type

When using Boost.Coroutine v2 (unidirectional coroutines), this type is:

pull_coroutine<void>

Constructor & Destructor Documentation

template<typename Handler>
boost::asio::basic_yield_context< Handler >::basic_yield_context ( const detail::weak_ptr< callee_type > &  coro,
caller_type ca,
Handler &  handler 
)
inline

Construct a yield context to represent the specified coroutine.

Most applications do not need to use this constructor. Instead, the spawn() function passes a yield context as an argument to the coroutine function.

Member Function Documentation

template<typename Handler>
basic_yield_context boost::asio::basic_yield_context< Handler >::operator[] ( boost::system::error_code ec) const
inline

Return a yield context that sets the specified error_code.

By default, when a yield context is used with an asynchronous operation, a non-success error_code is converted to system_error and thrown. This operator may be used to specify an error_code object that should instead be set with the asynchronous operation's result. For example:

template <typename Handler>
void my_coroutine(basic_yield_context<Handler> yield)
{
...
std::size_t n = my_socket.async_read_some(buffer, yield[ec]);
if (ec)
{
// An error occurred.
}
...
}

References boost::asio::basic_yield_context< Handler >::ec_.

Member Data Documentation

template<typename Handler>
caller_type& boost::asio::basic_yield_context< Handler >::ca_
template<typename Handler>
detail::weak_ptr<callee_type> boost::asio::basic_yield_context< Handler >::coro_
template<typename Handler>
Handler& boost::asio::basic_yield_context< Handler >::handler_

The documentation for this class was generated from the following file: