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

Asynchronous API Alternatives #135

Closed

Conversation

Maturin
Copy link

@Maturin Maturin commented May 6, 2024

What kind of change does this PR introduce?

Added a feature as described in #133

What is the current behavior?

#133

What is the new behavior?

Added the option to use the realtime library in an async programming environment.

Additional context

n/a

@Maturin Maturin requested a review from a team as a code owner May 6, 2024 07:52
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Maturin - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

# @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__)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
raise NotConnectedError(self.listen_async.__name__)
raise NotConnectedError(f"Failed to connect using {self.listen_async.__name__} in realtime/connection.py. Ensure the connection is established before invoking this method.")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two questions regarding this:

  1. This basically the same exception and exception message as in the ensure_connection function.
  2. As written in my comment, the question is if should create also an ensure_connection_async function/decorator. Using simply ensure_connection was marked as an error in PyCharm.

realtime/connection.py Outdated Show resolved Hide resolved
Comment on lines +68 to +77
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__)

Copy link
Contributor

Choose a reason for hiding this comment

The 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 listen_async and connect_async, but there are no corresponding tests to verify their behavior. It's crucial to ensure these methods handle asynchronous operations correctly and maintain the expected state of the connection.

Comment on lines +49 to +54
async def join_async(self) -> None:
"""
Wrapper for async def _join().
:return: None
"""
await self._join()
Copy link
Contributor

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 in Channel class also requires tests to ensure it integrates properly with the existing asynchronous infrastructure and behaves as expected under various conditions.

@@ -156,4 +156,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]}]")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug fix is not really related to the feature request. But I simply did it, while working on it. If you want, I can create a new bug ticket and solve it there.

@Maturin
Copy link
Author

Maturin commented May 6, 2024

This pull request has to be merged with PR #136.

@grdsdev
Copy link
Contributor

grdsdev commented Aug 19, 2024

V2 supports async now, implemented in #178

@grdsdev grdsdev closed this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants