...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Note | |
---|---|
This is an experimental feature. |
The experimental::deferred
, completion token takes
a call to an asynchronous operation's initiating function and turns it
into a function object that accepts a completion token. For example:
auto deferred_op = timer.async_wait( boost::asio::experimental::deferred); ... std::move(deferred_op)( [](boost::system::error_code ec){ ... });
or:
auto deferred_op = timer.async_wait( boost::asio::experimental::deferred); ... std::future<void> = std::move(deferred_op)( boost::asio::use_future);
The deferred token also supports chaining, to create simple compositions:
auto deferred_op = timer.async_wait( boost::asio::experimental::deferred( [&](boost::system::error_code ec) { timer.expires_after( std::chrono::seconds(1)); return timer.async_wait( boost::asio::experimental::deferred); }); ... std::future<void> = std::move(deferred_op)(boost::asio::use_future);
experimental::deferred, experimental::deferred_t, Deferred examples (C++14).