Skip to content

Commit 51cb3b9

Browse files
authored
removed tasks when done
Signed-off-by: Lumouille <[email protected]>
1 parent 64e9fb4 commit 51cb3b9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

discord/ext/tasks/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,17 @@ async def run_with_semaphore():
192192
async with self._semaphore:
193193
await self.coro(*args, **kwargs)
194194

195-
self._tasks.append(
196-
asyncio.create_task(
197-
(
198-
self.coro(*args, **kwargs)
199-
if self.overlap is True
200-
else run_with_semaphore()
201-
),
202-
name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}",
203-
)
195+
task = asyncio.create_task(
196+
(
197+
self.coro(*args, **kwargs)
198+
if self.overlap is True
199+
else run_with_semaphore()
200+
),
201+
name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}",
204202
)
203+
task.add_done_callback(self._tasks.remove)
204+
self._tasks.append(task)
205+
205206
_current_loop_ctx.reset(token)
206207
self._last_iteration_failed = False
207208
backoff = ExponentialBackoff()

0 commit comments

Comments
 (0)