en	Writing Composed Operations

en	Asynchronous operations are started by calling a free function or member function known as an asynchronous ['__async_initfn__]. This function accepts parameters specific to the operation as well as a __CompletionToken__. The token is either a completion handler, or a type defining how the caller is informed of the asynchronous operation result. Networking provides the special tokens __use_future__ and __yield_context__ for using futures and coroutines respectively. This system of customizing the return value and method of completion notification is known as the ['Universal Asynchronous Model] described in __N3747__, and a built in to __NetTS__. Here is an example of an initiating function which reads a line from the stream and echoes it back. This function is developed further in the next section:

en	This initiating function receives the dynamic buffer by lvalue-reference,

en	Authors using Beast can reuse the library's primitives to create their own initiating functions for performing a series of other, intermediate asynchronous operations before invoking a final completion handler. The set of intermediate actions produced by an initiating function is known as a [@http://blog.think-async.com/2009/08/composed-operations-coroutines-and-code.html ['composed operation]]. To ensure full interoperability and well-defined behavior, __Asio__ imposes requirements on the implementation of composed operations. These classes and functions make it easier to develop initiating functions and their composed operations:

en	Asynchronous Helpers

en	Name

en	Description

en	[link beast.ref.boost__beast__async_base `async_base`] [link beast.ref.boost__beast__stable_async_base `stable_async_base`]

en	This class is designed to be used as a base class when authoring composed asynchronous operations expressed as an intermediate completion handler. This eliminates the need for the extensive boilerplate to propagate the associated executor and the associated allocator.

en	[link beast.ref.boost__beast__allocate_stable `allocate_stable`]

en	For composed operation algorithms which need stable storage for temporary objects, this function may be used. Memory for the stable storage is allocated using the allocator associated with the final completion handler. The implementation automatically destroys the temporary object before the final completion handler is invoked, or when the intermediate completion handler is destroyed.

en	[link beast.ref.boost__beast__bind_handler `bind_handler`]

en	This function creates a new handler which, when invoked, calls the original handler with the list of bound arguments. Any parameters passed in the invocation will be substituted for placeholders present in the list of bound arguments. Parameters which are not matched to placeholders are silently discarded. The passed handler and arguments are forwarded into the returned handler, whose associated allocator and associated executor will be the same as those of the original handler.

en	[link beast.ref.boost__beast__bind_front_handler `bind_front_handler`]

en	This function creates a new handler which, when invoked, calls the original handler with the list of bound arguments, along with the list of invoked arguments at either the front or the back of the argument list. Placeholders are not supported. The passed handler and arguments are forwarded into the returned handler, whose associated allocator and associated executor will will be the same as those of the original handler.

en	[link beast.ref.boost__beast__saved_handler `saved_handler`]

en	This wrapper safely stores a completion handler so it may be invoked later, allowing an implementation to "pause" an operation until some condition is met.