Rewrite on_ready delay to actually make sense and prevent heavy sleep
This commit is contained in:
parent
f95ccf53e0
commit
cd9135b082
@ -340,11 +340,15 @@ class ConnectionState:
|
|||||||
|
|
||||||
# only real bots wait for GUILD_CREATE streaming
|
# only real bots wait for GUILD_CREATE streaming
|
||||||
if self.is_bot:
|
if self.is_bot:
|
||||||
while not launch.is_set():
|
while True:
|
||||||
# this snippet of code is basically waiting 2 seconds
|
# this snippet of code is basically waiting 2 seconds
|
||||||
# until the last GUILD_CREATE was sent
|
# until the last GUILD_CREATE was sent
|
||||||
launch.set()
|
try:
|
||||||
await asyncio.sleep(2)
|
await asyncio.wait_for(launch.wait(), timeout=2.0)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
launch.clear()
|
||||||
|
|
||||||
guilds = next(zip(*self._ready_state.guilds), [])
|
guilds = next(zip(*self._ready_state.guilds), [])
|
||||||
if self._fetch_offline:
|
if self._fetch_offline:
|
||||||
@ -729,7 +733,7 @@ class ConnectionState:
|
|||||||
# so we say.
|
# so we say.
|
||||||
try:
|
try:
|
||||||
state = self._ready_state
|
state = self._ready_state
|
||||||
state.launch.clear()
|
state.launch.set()
|
||||||
state.guilds.append((guild, unavailable))
|
state.guilds.append((guild, unavailable))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# the _ready_state attribute is only there during
|
# the _ready_state attribute is only there during
|
||||||
@ -1020,11 +1024,15 @@ class AutoShardedConnectionState(ConnectionState):
|
|||||||
|
|
||||||
async def _delay_ready(self):
|
async def _delay_ready(self):
|
||||||
launch = self._ready_state.launch
|
launch = self._ready_state.launch
|
||||||
while not launch.is_set():
|
while True:
|
||||||
# this snippet of code is basically waiting 2 seconds
|
# this snippet of code is basically waiting 2 seconds
|
||||||
# until the last GUILD_CREATE was sent
|
# until the last GUILD_CREATE was sent
|
||||||
launch.set()
|
try:
|
||||||
await asyncio.sleep(2.0 * self.shard_count)
|
await asyncio.wait_for(launch.wait(), timeout=2.0)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
launch.clear()
|
||||||
|
|
||||||
guilds = sorted(self._ready_state.guilds, key=lambda g: g[0].shard_id)
|
guilds = sorted(self._ready_state.guilds, key=lambda g: g[0].shard_id)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user