Skip to content

Commit

Permalink
[fix] asyncbackoff
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Dec 25, 2018
1 parent aca73c3 commit 7486d12
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aiomisc/backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __call__(self, func: T) -> T:
@wraps(func)
async def wrap(*args, **kwargs):
countdown = self.countdown
pause = self.pause

while countdown is None or countdown > 0:
started_at = monotonic()
Expand All @@ -49,13 +50,13 @@ async def wrap(*args, **kwargs):
return await func(*args, **kwargs)
except self.exceptions:
if countdown is not None:
countdown -= monotonic() - started_at + self.pause
countdown -= monotonic() - started_at + pause

if self.countdown <= 0:
if countdown <= 0:
raise

if self.pause > 0:
await asyncio.sleep(self.pause)
if pause > 0:
await asyncio.sleep(pause)

continue

Expand Down

0 comments on commit 7486d12

Please sign in to comment.