json-rpc
json-rpc copied to clipboard
Can't an AsyncJSONRPCResponseManager be added?
From what I understood so far to make an async version of json-rpc
's core one would need to just make an async version of JSONRPCResponseManager. I think the only way possible for that is duplicating the implementation of the sync version and changing the relevant methods' signature to be async. The procedure returned by the Dispatcher
would be awaited here.
Hi @HMaker you are right.
When json-rpc was started, I used it primarily for encoding/decoding. Then response manager came and then optional backends. One of the goal was to maintain compatibility with older python versions, e.g. 2.7 and the latter does not support async.
Then, python 3 introduced many useful features: type checking, connection protocols, etc. I tried to implement them into the original library, but it turned into if-then statements conditioning python version. Hence, I decided to fork json-rpc completely and implement an async version separately https://github.com/pavlov99/ajsonrpc It already has async manager initiated but it's still work in progress. I could prettify it (likely over the weekend) if you have an interested in using it.
@pavlov99 I just duplicated the JSONRPCResponseManager
and made an async version. I don't think its worth changing from json-rpc
to ajsonrpc
.
Thanks❤️🙏0xd71189c927f8039994da8e422951D1f5a8f18a4c
probably we can add JSONRpcBaseResponse.async_json
like this?
...
@property
async def async_json(self):
if isawaitable(self.data.get('result')):
self._data['result']=await self.data['result']
return self.serialize(self.data)
Although this is a bit tricky but it works well in our project