diff --git a/hikari/impl/stateful_event_manager.py b/hikari/impl/stateful_event_manager.py index a31236be75..8ad6574d1d 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,9 @@ 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. + 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) 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()))