From 2eb56e4f863475307eafa070d22e71d061641f6a Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Mon, 19 Oct 2020 13:08:05 -0700 Subject: Help channels: replace ready event with awaiting the init task The event is redundant since awaiting the task accomplishes the same thing. If the task is already done, the await will finish immediately. If the task gets cancelled, the error is raised but discord.py suppress it in both commands and event listeners. --- bot/exts/help_channels/_cog.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py index 5c4a0d972..bea1f65e6 100644 --- a/bot/exts/help_channels/_cog.py +++ b/bot/exts/help_channels/_cog.py @@ -83,7 +83,6 @@ class HelpChannels(commands.Cog): # Asyncio stuff self.queue_tasks: t.List[asyncio.Task] = [] - self.ready = asyncio.Event() self.on_message_lock = asyncio.Lock() self.init_task = self.bot.loop.create_task(self.init_cog()) @@ -264,11 +263,9 @@ class HelpChannels(commands.Cog): self.close_command.enabled = True await self.init_available() + self.report_stats() log.info("Cog is ready!") - self.ready.set() - - self.report_stats() def report_stats(self) -> None: """Report the channel count stats.""" @@ -439,8 +436,9 @@ class HelpChannels(commands.Cog): if not is_available or _channel.is_excluded_channel(channel): return # Ignore messages outside the Available category or in excluded channels. - log.trace("Waiting for the cog to be ready before processing messages.") - await self.ready.wait() + if not self.init_task.done(): + log.trace("Waiting for the cog to be ready before processing messages.") + await self.init_task log.trace("Acquiring lock to prevent a channel from being processed twice...") async with self.on_message_lock: -- cgit v1.2.3