Skip to content

Commit a9dba27

Browse files
diceroll123Rapptz
authored andcommitted
[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`.
1 parent 87dd046 commit a9dba27

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

discord/ext/tasks/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ async def _loop(self, *args, **kwargs):
109109
raise
110110
await asyncio.sleep(backoff.delay())
111111
else:
112+
await sleep_until(self._next_iteration)
113+
112114
if self._stop_next_iteration:
113115
return
114116
self._current_loop += 1
115117
if self._current_loop == self.count:
116118
break
117-
118-
await sleep_until(self._next_iteration)
119119
except asyncio.CancelledError:
120120
self._is_being_cancelled = True
121121
raise

0 commit comments

Comments
 (0)