I want to use boost fibers to accomplish async communication with an external service. I use a set of promise and future for each individual fiber to be called on a separate reader fiber in order to wake up the originator fiber that waits for a future.
The problem is I can not figure out the type of the lambda function. I tried to use std::function and std::bind. But I did not manage to figure out the right type.
The callback is in the following structure:
struct AsyncClientCall {
std::string response;
bool status; // Storage for the status of the RPC upon completion.
// what is the proper type for this
std::function<void()> callback;
};
It works for PODs, such as:
asyncCall->callback = [i = msg] () mutable {
std::cout << "release the lock: " << i << std::endl;
};
But it does not with boost::fibers::promise, since there is no copy constructor:
asyncCall->callback = [p = std::move(promiseRsp)] () mutable {
p.set_value();
};
However there is no problem with the lambda itself, since this works fine
auto callback = [p = std::move(promiseRsp)] () mutable {
p.set_value();
};
So my question is how to get around this properly if I want to use promise for synchronisation between fibers