json-rpc icon indicating copy to clipboard operation
json-rpc copied to clipboard

Can't an AsyncJSONRPCResponseManager be added?

Open HMaker opened this issue 4 years ago • 4 comments

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.

HMaker avatar Sep 07 '20 23:09 HMaker

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 avatar Sep 08 '20 07:09 pavlov99

@pavlov99 I just duplicated the JSONRPCResponseManager and made an async version. I don't think its worth changing from json-rpc to ajsonrpc.

HMaker avatar Sep 08 '20 17:09 HMaker

Thanks❤️🙏0xd71189c927f8039994da8e422951D1f5a8f18a4c

S1983tt avatar Oct 20 '22 11:10 S1983tt

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

lin-calvin avatar Jul 09 '23 11:07 lin-calvin