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

async_initiate
PrevUpHomeNext

Helper function for implementing an asynchronous operation's initiating function.

template<
    typename CompletionToken,
    completion_signature... Signatures,
    typename Initiation,
    typename... Args>
DEDUCED async_initiate(
    Initiation && initiation,
    type_identity_t< CompletionToken > & token,
    Args &&... args);

The async_initiate function wraps the async_result trait. It automatically performs the necessary decay and forward of the completion token, and also enables backwards compatibility with legacy completion token implementations.

Parameters

initiation

A function object that will be called to launch the asynchronous operation. It receives the concrete completion handler as its first argument, followed by any additional arguments passed to async_initiate.

token

The completion token provided by the user. This will be transformed into a concrete completion handler by the async_result trait.

args

Additional arguments to be forwarded to the initiation function object.

Return Value

The return value is determined by the async_result specialisation for the completion token type. For callback-based tokens, returns void. For other tokens such as use_future or use_awaitable, returns the corresponding future or awaitable type.

Remarks

Asynchronous operation implementations should use this function rather than directly using the async_result trait, or the legacy async_completion helper template.

For a more detailed discussion of the role of async_result and async_initiate, see the overview documentation for completion token.

Requirements

Header: boost/asio/async_result.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext