backoff
backoff copied to clipboard
Allow Custom Sleep Function
I think it would be great to add a sleep
argument which defaults to asyncio.sleep
to improve support for event loops besides asyncio
, while keeping it working out of the box for asyncio
. I like backoff and would like to stick with it, but it ended up being too much of a hassle to get it working with trio.
tenacity
has this feature, with the following syntax/explanation.
You can even use alternative event loops such as curio or Trio by passing the correct sleep function:
@retry(sleep=trio.sleep)
async def my_async_function(loop):
await asks.get('https://example.org')
Is this just as simple as await
ing a different sleep function here?
https://github.com/litl/backoff/blob/master/backoff/_async.py#L94
if I'm understanding it looks like this would be very easy to accomodate
Yes. That should be it! (Of course also adding keyword argument and passing it through as well)