More pythonic API by using asyncio.Queue
#218
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my attempt to make the API more pythonic.
For each subscription on the WebSocket we are now creating a
asyncio.Queue.https://docs.python.org/3/library/asyncio-queue.html
This way, we do not have to count the number of received responses, but can let
asyncio.gatherhandle all that calculation for us as you can see indetails.py. The usage ofasyncio.Queueallows further simplification in other files, which are not in this PR.recv2creates a loop that is feeding these queues with newly arrived messages and is therefore aasyncio.Taskthat needs to be started at the beginning. This is currently done indetails_loopbut I would rather collect that at a more centralized place.https://docs.python.org/3/library/asyncio-task.html#asyncio.Task
The intention is not to introduce these new
2-suffixed function, but to show how the other functions could look like.If the overall idea looks good to you, then I can change all the other functions as well to follow this scheme and undraft this PR.