Skip to content

Commit

Permalink
async: schedule next request earlier to actually delay async requests
Browse files Browse the repository at this point in the history
  • Loading branch information
d70-t committed Mar 11, 2022
1 parent 8473960 commit 5286e26
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ipfsspec/async_ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ def _gws_in_priority_order(self):
async def _gw_op(self, op):
for _ in range(self.max_backoff_rounds):
for state, gw in self._gws_in_priority_order:
not_before = state.next_request_time
if not state.reachable:
state.trying_to_reach()
else:
state.schedule_next()
now = time.monotonic()
if state.next_request_time > now:
await asyncio.sleep(state.next_request_time - now)
if not_before > now:
await asyncio.sleep(not_before - now)
logger.debug("tring %s", gw)
try:
res = await op(gw)
Expand Down

0 comments on commit 5286e26

Please sign in to comment.