Skip to content

Conversation

@semmel
Copy link

@semmel semmel commented Jul 27, 2018

We use jsonrpc-lean to expose a C++ VoIP and SIP client via a Unix domain socket to a Node.js client on the same machine. The number of methods which need to be wired through JSON-RPC Api and the total count of calls can be reduced if longer running methods (like playing a WAV file over VoIP) are permitted to run as background threads thus not blocking the JSON-RPC server for parallel commands and without polling responding to the JSON-RPC request after the time the operation completed.

In single-threaded JavaScript one uses callbacks which are nicely wrapped by Promises. C++ Futures with TS for Concurrency for C++14 together with C++ Promises wrap C++ threads very similar to JS Promises. Both make creating and consuming background computations easy. Unfortunately the JSPromise-like C++ Future::then callback interface is still on the roadmap for the C++ standard. Thus the introduced dependency on the "polyfill" in boost::thread makes the setup of jsonrpc-lean more complicated. I.e. boost::thread needs to be available as a library.

The implementation of asynchronous server request offered here is far from perfect. Mostly because I couldn't figure out easy how the intricate template machinery for storing the strongly typed methods in their return values and parameters by the Dispatcher works.
However, I attempted to minimise the changes to the public and internal jsonrpc-lean API. Except for the problem of future-returning Lambdas (see the section in the Readme) I just added the single new method Dispatcher::asyncHandleRequest.

@uskr
Copy link
Owner

uskr commented Jul 27, 2018

Thia is indeed a nice addition. I will dive in all the changes you posted to see what I can merge, without breaking the basic requirements of this project. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants