Skip to content

Retry as context_manager #12

Description

@yeahframeoff

My proposal is to make retry function possible to be used as context manager which wraps original function in the with block:

>>> from asynctest import CoroutineMock
>>> async def case1():
...     fn = CoroutineMock(side_effect=[RuntimeError, 'success'])
...     return await fn()
>>> async def case2():
...     fn = CoroutineMock(side_effect=[RuntimeError, 'success'])
...     with retry(fn) as wrapped:
...         return await wrapped() 
>>> asyncio.get_event_loop().run_until_complete(case1())
RuntimeError:
...
>>> asyncio.get_event_loop().run_until_complete(case2())
'success'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions