Skip to content

Commit 11c3ab5

Browse files
committed
usage of set instead of list for race condition
1 parent 6546270 commit 11c3ab5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

discord/ext/tasks/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(
125125
self._is_being_cancelled = False
126126
self._has_failed = False
127127
self._stop_next_iteration = False
128-
self._tasks: list[asyncio.Task[Any]] = []
128+
self._tasks: set[asyncio.Task[Any]] = set()
129129

130130
if self.count is not None and self.count <= 0:
131131
raise ValueError("count must be greater than 0 or None.")
@@ -200,8 +200,8 @@ async def run_with_semaphore():
200200
),
201201
name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}",
202202
)
203-
task.add_done_callback(self._tasks.remove)
204-
self._tasks.append(task)
203+
task.add_done_callback(lambda t: self._tasks.discard(t))
204+
self._tasks.add(task)
205205

206206
_current_loop_ctx.reset(token)
207207
self._last_iteration_failed = False

0 commit comments

Comments
 (0)