Beast Logo

PrevUpHomeNext

bind_handler

Bind parameters to a completion handler, creating a new handler.

template<
    class Handler,
    class... Args>
implementation-defined
bind_handler(
    Handler&& handler,
    Args&&... args);

This function creates a new handler which, when invoked with no parameters, calls the original handler with the list of bound arguments. The passed handler and arguments are forwarded into the returned handler, which provides the same io_service execution guarantees as the original handler.

Unlike io_service::wrap, the returned handler can be used in a subsequent call to io_service::post instead of io_service::dispatch, to ensure that the handler will not be invoked immediately by the calling function.

Example:

template<class AsyncReadStream, class ReadHandler>
void
do_cancel(AsyncReadStream& stream, ReadHandler&& handler)
{
    stream.get_io_service().post(
        bind_handler(std::forward<ReadHandler>(handler),
            boost::asio::error::operation_aborted, 0));
}
Parameters

handler

The handler to wrap.

args

A list of arguments to bind to the handler. The arguments are forwarded into the returned object.

Requirements

Header: beast/core/bind_handler.hpp

Convenience header: beast/core.hpp


PrevUpHomeNext