Skip to content

Commit e6c8100

Browse files
committed
fix(tasks): support change_interval before first loop run (#1291)
1 parent 429af20 commit e6c8100

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

changelog/1290.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
|tasks| Correctly handle :meth:`Loop.change_interval <ext.tasks.Loop.change_interval>` when called from :meth:`~ext.tasks.Loop.before_loop` or through other means before initial loop run.

disnake/ext/tasks/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,9 @@ def change_interval(
689689
self._time = self._get_time_parameter(time)
690690
self._sleep = self._seconds = self._minutes = self._hours = MISSING
691691

692-
if self.is_running():
692+
# `_last_iteration` can be missing if `change_interval` gets called in `before_loop` or
693+
# before the event loop ticks after `start()`
694+
if self.is_running() and self._last_iteration is not MISSING:
693695
if self._time is not MISSING:
694696
# prepare the next time index starting from after the last iteration
695697
self._prepare_time_index(now=self._last_iteration)

0 commit comments

Comments
 (0)