-
Notifications
You must be signed in to change notification settings - Fork 186
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
base: main
Are you sure you want to change the base?
Conversation
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))) |
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.
If there's already an event loop, this will fail without nest_asyncio
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.
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.
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.
Lgtm honestly, nice
This PR ports the last method missing from
AsyncSessionClient
,get_task_result_stream
.Fixes #335
Notes for the reviewer:
Coroutine[AsyncGenerator]
when converted withasync_to_sync
returnAsyncGenerator
, 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 listClient