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

Add AsyncDecorator.asyncio() #125

Merged
merged 11 commits into from
Aug 17, 2023
Merged

Conversation

dkang-quora
Copy link
Contributor

This PR adds AsyncDecorator.asyncio(), which returns a coroutine object that can be awaited with asyncio.

The method is useful for codebase that is migrating from asynq to asyncio.

Limitations:

  • BatchItem is not supported
  • Synchronous calls are not allowed

To workaround these limitations, the PR also adds a new parameter asyncio_fn to the asynq decorator.

@asynq.asynq(asyncio_fn=asyncio_get)
def get():
    yield ...

async def asyncio_get():
    await ...

In this example, get.asyncio() is forwarded to asyncio_get().

asynq/decorators.py Show resolved Hide resolved
asynq/asynq_to_async.py Outdated Show resolved Hide resolved
asynq/tests/test_asynq_to_async.py Outdated Show resolved Hide resolved
asynq/tools.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
@JelleZijlstra JelleZijlstra merged commit cf6ebcd into quora:master Aug 17, 2023
10 checks passed
@dkang-quora dkang-quora deleted the asyncio branch August 17, 2023 22:34
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.

None yet

2 participants