Beast Logo

PrevUpHomeNext

Asynchronous interface

Asynchronous versions are available for all functions:

websocket::opcode op;
ws.async_read(op, sb,
    [](boost::system::error_code const& ec)
    {
        ...
    });

Calls to asynchronous initiation functions support the extensible asynchronous model developed by the Boost.Asio author, allowing for traditional completion handlers, stackful or stackless coroutines, and even futures:

void echo(websocket::stream<ip::tcp::socket>& ws,
    boost::asio::yield_context yield)
{
    ws.async_read(sb, yield);
    std::future<websocket::error_code> fut =
        ws.async_write, sb.data(), boost::use_future);
    ...
}

PrevUpHomeNext