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

Allow asynchronous callbacks for AsyncRetrying parameters #363

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

Conversation

mastizada
Copy link

@mastizada mastizada commented Sep 23, 2022

This change will allow both async and sync functions to be used as callable parameters for Async retries.

Docs are not updated, please, inform if any other changes are needed. Thank you very much for your review.

Fixes #249

Copy link
Owner

@jd jd left a comment

Choose a reason for hiding this comment

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

Could we try to DRY the iter method? I understand we need to re-define it but it'd be great if we could share most of the code.

return await func(retry_state)
return func(retry_state)

async def iter(self, retry_state: "RetryCallState") -> typing.Union[DoAttempt, DoSleep, typing.Any]: # noqa
Copy link
Author

Choose a reason for hiding this comment

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

@jd I also wanted to use some base method to avoid re-defining the iter method again, however, one of them is sync def iter and other one is async async def iter. Any ideas how to make it DRY?

I wanted to use handle_custom_function to handle sync/async calls, however, if we make handle_custom_function sync function, then it might need to use asyncio.get_event_loop() to run awaitable functions (running async functions from sync function).

Copy link
Author

@mastizada mastizada Sep 27, 2022

Choose a reason for hiding this comment

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

@jd any ideas? I would love to have a progress with this PR and start using async callbacks for retry_error_callback

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.

Is an async retry_error_callback possible?
2 participants