I'm trying to rewrite a project using boost::asio::spawn
coroutines. Some parts of the project cannot be changed. For example, the storage protocol library is also written with boost::asio
, but without coroutines.
The problem is how to convert yield_context
into a normal callback (a boost::function
object or a classical functor).
This is what we have in the storage library API:
void async_request_data(uint64_t item_id, boost::function< void(Request_result *) > callback);
As we know from examples, the asio yield context can be used like this:
my_socket.async_read_some(boost::asio::buffer(data), yield);
In this case a boost::asio::yield_context
object serves as a callback for async_read_some. I would like to pass a yield object as the second argument to async_request_data
, so i can use it in a synchronous manner.
How can this be done? I think it may be possible via some proxy-object, possibly using an approach based on asio_handler_invoke. But I am having trouble seeing how to do this.