Closed gregmedd closed 4 months ago
RpcClient::invokeMethod() returns std::future, which does not provide the really asynchronous API.
The user has a few options to deal with the response and all of them are bad:
I understood that the callback variation of invokeMethod() was removed because the callback is invoked in the up-cpp context.
I have another suggestion: To add an optional parameter of std::counting_semaphore* to invokeMethod(). If the provided semaphore is not null, up-cpp will call to release() right after it called to promise::set_value(). It allows to the user to open a single thread that will sleep on the this semaphore, and to check all the response futures.
Pros:
Cons:
Having thought on this more, UTransport already has a safe shutdown process for its components. Only RpcClient
would need to add this interface.
I've also just been informed that there is active discussion on changing the requirements of the RpcClient API in up-spec, so this issue will be on hold until that is decided.
@sanjok-itin - I've got confirmation that the spec is being relaxed in this area and that callbacks instead of futures would be acceptable in the API. I'm going to investigate and make sure we can support that, then put it on our roadmap. If we can switch to callbacks, then we might not need the shutdown interface at all (depending on the RPC client design).
@sanjok-itin has pointed out that waiting on std::futures does not allow for a shutdown path. Either threads waiting on futures need to wake periodically to check if they need to stop waiting, or we need to wake them by breaking the promises.
We should look into implementing some sort of shutdown interface so that we can break promises and block any new calls to the transport APIs.
Alternatively, returning some sort of other waitable object that can be signaled from both ends of the connection could be used, or we could return something that can be waited on as a group (e.g. using
poll()
orselect()
orepoll()
)