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

feat: add get_task_result_stream to new client #351

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

masci
Copy link
Member

@masci masci commented Nov 6, 2024

This PR ports the last method missing from AsyncSessionClient, get_task_result_stream.

Fixes #335

Notes for the reviewer:

  • async methods returning Coroutine[AsyncGenerator] when converted with async_to_sync return AsyncGenerator, that we can't use in sync calls. To overcome this limitation, generator_wrapper was added that consumes the async generator under the hood and returns a list
  • end-to-end tests were update to use Client
  • unit tests were added to cover the new wrapper

@coveralls
Copy link

coveralls commented Nov 6, 2024

Coverage Status

coverage: 71.351% (+3.2%) from 68.189%
when pulling 9ac6ea6 on massi/client-streaming
into b96db7a on main.

func: Callable[_P, AsyncGenerator[_G, None]], /, *args: Any, **kwargs: Any
) -> Callable[_P, list[_G]]:
def new_func(*fargs: Any, **fkwargs: Any) -> list[_G]:
return asyncio.run(_async_gen_to_list(func(*fargs, **fkwargs)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's already an event loop, this will fail without nest_asyncio

Copy link
Member Author

@masci masci Nov 7, 2024

Choose a reason for hiding this comment

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

Good catch. This line in particular is not even the problem, async_to_sync would raise a runtime error if you try to use the converted sync code in an async function within an existing loop (fair enough, why would you want all the overhead?). I added a check so it's our client raising RuntimeError now with a specific message explaining what's happening.

Copy link
Collaborator

@logan-markewich logan-markewich left a comment

Choose a reason for hiding this comment

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

Lgtm honestly, nice

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.

Port existing clients to the new Client class
3 participants