-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Asynchronous API Alternatives #135
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -65,6 +65,18 @@ def listen(self) -> None: | |||||
loop = asyncio.get_event_loop() # TODO: replace with get_running_loop | ||||||
loop.run_until_complete(asyncio.gather(self._listen(), self._keep_alive())) | ||||||
|
||||||
async def listen_async(self) -> None: | ||||||
""" | ||||||
Wrapper for async def _listen() and async def _keep_alive() to expose an async interface. | ||||||
:return: None | ||||||
""" | ||||||
# @ensure_connection is definitely nicer, but I don't know if it is also | ||||||
# working for asynchronous functions. | ||||||
if not self.connected: | ||||||
raise NotConnectedError(self.listen_async.__name__) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Consider adding a more descriptive error message. Providing a more detailed error message can help in debugging and understanding the context of the error when it occurs.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have two questions regarding this:
|
||||||
|
||||||
Comment on lines
+68
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (testing): Missing tests for the new asynchronous methods. The PR introduces new asynchronous methods such as |
||||||
await asyncio.gather(self._listen(), self._keep_alive()) | ||||||
|
||||||
async def _listen(self) -> None: | ||||||
""" | ||||||
An infinite loop that keeps listening. | ||||||
|
@@ -103,6 +115,12 @@ def connect(self) -> None: | |||||
loop.run_until_complete(self._connect()) | ||||||
self.connected = True | ||||||
|
||||||
async def connect_async(self) -> None: | ||||||
""" | ||||||
Wrapper for async def _connect() to expose a async interface. | ||||||
""" | ||||||
await self._connect() | ||||||
|
||||||
async def _connect(self) -> None: | ||||||
ws_connection = await websockets.connect(self.url) | ||||||
|
||||||
|
@@ -156,4 +174,4 @@ def summary(self) -> None: | |||||
""" | ||||||
for topic, chans in self.channels.items(): | ||||||
for chan in chans: | ||||||
print(f"Topic: {topic} | Events: {[e for e, _ in chan.callbacks]}]") | ||||||
print(f"Topic: {topic} | Events: {[e for e, _ in chan.listeners]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (testing): Tests needed for
join_async
method.The addition of
join_async
inChannel
class also requires tests to ensure it integrates properly with the existing asynchronous infrastructure and behaves as expected under various conditions.