pydactyl
pydactyl copied to clipboard
Add async support
This would only be feasible if it leaves the existing behavior intact as synchronous calls. There are ways to write the code as async and have a wrapper that generates a synchronous version. This could potentially be refactored so that pyadctyl exposes get_servers() and async_get_servers() without impacting the existing behavior.
Some relevant links
https://discuss.python.org/t/how-can-async-support-dispatch-between-sync-and-async-variants-of-the-same-code/15014/14
https://gist.github.com/blink1073/969aeba85f32c285235750626f2eadd8
Hi, @iamkubi. I made a partially working version with asynchronous calls, and I have a couple of questions for you.
Firstly, what should the documentation look like for synchronous functions? Should it just copy-paste from asynchronous methods or refer to them or something else? The same question I have for tests: if synchronous versions will call asynchronous ones, then it is not necessary to test asynchronous ones directly, am I right?
Or how will synchronous calls work? You can call asynchronous in a new(or existing) loop/thread/etc. But you can just use the existing synchronous requests.Session(or httpx.Client) and don't bother with it. Also, is there no problem here if I use httpx library for asynchronous requests?
HTTPX is fine, I would probably use something like this for async as to not double docs size for nothing.
from pydactyl import PterodactylClient
api = AsyncPterodactylClient('debug', 'anything')
All methods of AsyncPterodactylClient would then just be async, you wouldn't even have to rename them.
Please let me know whether that's in your interest and I'll work on it.