From dbfabc581c167d39449543ce2b890807df4f361d Mon Sep 17 00:00:00 2001 From: Faster Speeding Date: Mon, 7 Sep 2020 22:28:51 +0100 Subject: [PATCH 1/2] create a task with shard.request_guild_members instead of awaiting it in places to avoid it blocking other stuff unnecessarily. --- hikari/impl/stateful_event_manager.py | 4 +++- tests/hikari/hikari_test_helpers.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hikari/impl/stateful_event_manager.py b/hikari/impl/stateful_event_manager.py index a31236be75..febb5acb91 100644 --- a/hikari/impl/stateful_event_manager.py +++ b/hikari/impl/stateful_event_manager.py @@ -25,6 +25,7 @@ __all__: typing.Final[typing.List[str]] = ["StatefulEventManagerImpl"] +import asyncio import typing from hikari import channels @@ -166,7 +167,8 @@ async def on_guild_create(self, shard: gateway_shard.GatewayShard, payload: data # payload if presence intents are also declared, so if this isn't the case then we also want # to chunk small guilds. if (event.guild.is_large or not presences_declared) and members_declared: - await shard.request_guild_members(event.guild) + # We create a task here instead of awaiting the result to avoid any rate-limits from delaying dispatch. + asyncio.create_task(shard.request_guild_members(event.guild)) await self.dispatch(event) diff --git a/tests/hikari/hikari_test_helpers.py b/tests/hikari/hikari_test_helpers.py index 51d22d4281..05f439bc9f 100644 --- a/tests/hikari/hikari_test_helpers.py +++ b/tests/hikari/hikari_test_helpers.py @@ -267,3 +267,8 @@ async def wrapper(*args, **kwargs): return decorator(decorated_func) else: return decorator + + +async def gather_all_tasks(): + """Ensure all created tasks except the current are finished before asserting anything.""" + await asyncio.gather(*(task for task in asyncio.all_tasks() if task is not asyncio.current_task())) From 35681619006967f8ebf3d828d4d64c5ea15c36ae Mon Sep 17 00:00:00 2001 From: Faster Speeding Date: Mon, 7 Sep 2020 23:00:47 +0100 Subject: [PATCH 2/2] Add name to guild create members request task. --- hikari/impl/stateful_event_manager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hikari/impl/stateful_event_manager.py b/hikari/impl/stateful_event_manager.py index febb5acb91..8ad6574d1d 100644 --- a/hikari/impl/stateful_event_manager.py +++ b/hikari/impl/stateful_event_manager.py @@ -168,7 +168,8 @@ async def on_guild_create(self, shard: gateway_shard.GatewayShard, payload: data # to chunk small guilds. if (event.guild.is_large or not presences_declared) and members_declared: # We create a task here instead of awaiting the result to avoid any rate-limits from delaying dispatch. - asyncio.create_task(shard.request_guild_members(event.guild)) + coroutine = shard.request_guild_members(event.guild) + asyncio.create_task(coroutine, name=f"{event.shard.id}:{event.guild.id} guild create members request") await self.dispatch(event)