async_retrying
async_retrying copied to clipboard
Retry as context_manager
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'
Nice idea, it will be implemented soon.
it will be async context manager, like
async with retry(...)
Thanks for the idea!
Hey @hellysmile , did you have a chance to implement it? It would be very helpful.