async_retrying icon indicating copy to clipboard operation
async_retrying copied to clipboard

Retry as context_manager

Open yeahframeoff opened this issue 8 years ago • 2 comments

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'

yeahframeoff avatar Oct 30 '17 13:10 yeahframeoff

Nice idea, it will be implemented soon.

it will be async context manager, like

async with retry(...)

Thanks for the idea!

hellysmile avatar Oct 30 '17 13:10 hellysmile

Hey @hellysmile , did you have a chance to implement it? It would be very helpful.

hzlmn avatar Nov 09 '17 12:11 hzlmn