I use cpprestsdk (ex-Casablanca) and Boost.Asio, and I need to yield (for other tasks) while waiting for request to complete.
I use this:
void client::make_request(boost::asio::yield_context yield)
{
http_client client;
uri = "http://example.com/uri";
auto request_task = client.request(methods::GET, uri);
boost::asio::deadline_timer yield_timer(io_service_);
while (!request_task.is_done())
{
// yield, for example for 10 ms
yield_timer.expires_from_now(default_yield_time_);
yield_timer.async_wait(yield);
}
auto response = request_task.get();
// ...
// parse response, etc.
// ...
}
Is there a more elegant way (not obvious for me sadly :-( ) to do this yielding without using asio timers?