Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

basic_eager_async_operation

An eagerly-initiated asynchronous operation that is awaited later.

template<
    typename Executor,
    typename... Signatures>
class basic_eager_async_operation
Member Functions

Name

Description

basic_eager_async_operation [constructor]

Move constructor.
—
Converting move constructor.

cancel

Cancel the operation.

operator()

Wait for the operation to complete, consuming the eager operation.

operator=

Move assignment operator.

ready

Whether the operation's result is ready to be taken without waiting.

A basic_eager_async_operation is a move-only handle to a single asynchronous operation that has already been started. It is produced by passing the eager completion token to an asynchronous operation, and is more conveniently named using the eager_async_operation alias.

The operation is consumed by invoking it as an rvalue, exactly once, which starts an asynchronous wait for its completion:

boost::asio::eager_async_operation<
  void(boost::system::error_code, std::size_t)> op
    = socket.async_read_some(buffer, boost::asio::eager);

// ... do other work while the read runs ...

std::move(op)([](boost::system::error_code e, std::size_t n) { ... });

Destroying a handle that has not been waited on detaches from the operation. The operation is not cancelled. It continues to run, and its result is discarded. Although the handle may be moved as necessary, ownership of the objects the operation refers to is retained by the caller, which must guarantee that they remain valid until the operation completes. To cancel the operation, call cancel, or bind a cancellation slot to the completion handler passed when waiting.

Thread Safety

Distinct objects: Safe.

Shared objects: Unsafe.

An eager operation adds no thread safety to the operation that it wraps. A cancellation request is emitted on the thread that requests it, so it is the caller's responsibility to do so from a context that is safe with respect to the operation's execution.

See Also

Eager operations

Requirements

Header: boost/asio/eager.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext