cpp-netlib/cpp-netlib — pull request #435 by deanberris (2014-09-02 17:01:27+00:00)
Title: Initial implementation of when_ready(...)

This is a first quick attempt at implementing a 'when_ready(...)'
wrapper which allows users to write:

http::client client;
auto response = client.get("http://example.com");
when_ready(response,
[](const http::response& r, const boost::system::error_code& ec))
{
// in here, ready(r) is true and ec is set!
});

We also support a version of when_ready(...) that takes a thread pool
as the final parameter determining a different set of threads where the
completion callback is invoked.

This isn't quite ready yet because there are a couple of issues:

- We need to define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION so that
we can leverage the '.then(...)' functionality in Boost.Thread's
future implementation.
- We hide the functionality behind a BOOST_NETWORK_ENABLE_WHEN_READY
macro so that we can allow users to opt-in to this new functionality.
- Currently we assume that the '.then(...)' functionality is available
in the implementation. We may probably set this in some centralized
configuration header unique to cpp-netlib so macro settings can be
defined in a single location.

TODO's:

- Un-hide the functionality from BOOST_NETWORK_ENABLE_WHEN_READY
probably in a later release candidate.
- Implement an 'await' wrapper that does the reverse, which blocks the
current thread.
- Implement a 'defer' wrapper that is equivalent to moving the await
into a callback that's scheduled in a different threadpool.