[tasks] Move the Loop's sleep to be before exit conditions
This change makes it more so that `Loop.stop()` gracefully makes the current iteration the final one, by waiting AND THEN returning. The current implementation is closer to `cancel`, while also not. I encountered this because I was trying to run a `@tasks.loop(count=1)`, and inside it I print some text and change the interval, and in an `after_loop`, I restart the loop. Without this change, it immediately floods my console, due to not waiting before executing `after_loop`.
This commit is contained in:
parent
6ba3d89076
commit
ef9bb79e91
@ -111,13 +111,13 @@ class Loop:
|
|||||||
raise
|
raise
|
||||||
await asyncio.sleep(backoff.delay())
|
await asyncio.sleep(backoff.delay())
|
||||||
else:
|
else:
|
||||||
|
await sleep_until(self._next_iteration)
|
||||||
|
|
||||||
if self._stop_next_iteration:
|
if self._stop_next_iteration:
|
||||||
return
|
return
|
||||||
self._current_loop += 1
|
self._current_loop += 1
|
||||||
if self._current_loop == self.count:
|
if self._current_loop == self.count:
|
||||||
break
|
break
|
||||||
|
|
||||||
await sleep_until(self._next_iteration)
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
self._is_being_cancelled = True
|
self._is_being_cancelled = True
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user