Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't an AsyncJSONRPCResponseManager be added? #116

Open
HMaker opened this issue Sep 7, 2020 · 4 comments
Open

Can't an AsyncJSONRPCResponseManager be added? #116

HMaker opened this issue Sep 7, 2020 · 4 comments
Labels

Comments

@HMaker
Copy link

HMaker commented Sep 7, 2020

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.

@pavlov99
Copy link
Owner

pavlov99 commented Sep 8, 2020

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.

@HMaker
Copy link
Author

HMaker commented Sep 8, 2020

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

@S1983tt
Copy link

S1983tt commented Oct 20, 2022

Thanks❤️🙏0xd71189c927f8039994da8e422951D1f5a8f18a4c

@lin-calvin
Copy link

lin-calvin commented Jul 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants