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 #133

Open
Maturin opened this issue May 5, 2024 · 2 comments
Open

Asynchronous API Alternatives #133

Maturin opened this issue May 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Maturin
Copy link

Maturin commented May 5, 2024

Feature request

Is your feature request related to a problem? Please describe.

I want to be able to have asynchronous tasks parallel to realtime-py. Basically the same mentioned @albertpurnama in a comment to #66 . While #66 is about using listen() in separate thread, this request and I guess the one from @albertpurnma, is to have an official public asynchronous API, instead of using private _ functions.

Describe the solution you'd like

I would like to add async siblings to the following functions:

  • Socket.listen -> Socket.listen_async
  • Socket.connect -> Socket.connect_async
  • Channel.join -> Channel.join_async

This would the naming convention proposed here. I know this is no official document. But I couldn't find a better one.

The async function are basically a public wrapper around the private async functions.

Furthermore, I don't know if my list above is sufficient. Please extend the list. But it was sufficient, when I tried it some time ago.

Describe alternatives you've considered

Instead of creating a wrapper for the private async functions, they could be renamed.

But this would create more implementation effort for this ticket, and I like the idea of having a public function, which remains unchanged, even if internal stuff changes.

Additional context

n/a

@Maturin Maturin added the enhancement New feature or request label May 5, 2024
@Maturin Maturin changed the title Asynchronouos API Atlternatives Asynchronous API Alternatives May 5, 2024
@albertpurnama
Copy link

I like it.

So essentially, calling the internal functions like _join inside join_async. Will work for my case and seems like a simple change!

I tried to do fancy asyncio management stuff inside join itself to sort of handle scheduling to existing event loop, but I guess my understanding of how event loop works is still off by a mile.

@Maturin
Copy link
Author

Maturin commented May 6, 2024

I am not an expert of the async Python programming myself. I believe it might be possible to get an event loop and use that. But that is basically, what the current join function does.

IMHO the biggest disadvantage of this approach that you turn a possibly async call into a synchronously call. Actually I wanted to do something like this

async def foo():
    s = Socket(url)
    await s.connect_async()
    # ...

for taking advantage of the asynchronous programming model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants