pytr icon indicating copy to clipboard operation
pytr copied to clipboard

More pythonic API by using `asyncio.Queue`

Open nagy opened this issue 7 months ago • 1 comments

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.gather handle all that calculation for us as you can see in details.py. The usage of asyncio.Queue allows further simplification in other files, which are not in this PR. recv2 creates a loop that is feeding these queues with newly arrived messages and is therefore a asyncio.Task that needs to be started at the beginning. This is currently done in details_loop but 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.

nagy avatar May 20 '25 09:05 nagy

That looks nice. This could also make the Timeline module cleaner and better readable.

ExploracuriousAlex avatar Nov 12 '25 18:11 ExploracuriousAlex