Skip to content

Commit b2b8625

Browse files
committed
♻️ move sane_wait_for to private
1 parent 1d70dec commit b2b8625

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

discord/state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
Union,
4444
)
4545

46-
from .utils.private import parse_time
46+
from .utils.private import parse_time, sane_wait_for
4747
from . import utils
4848
from .utils.private import get_as_snowflake
4949
from .activity import BaseActivity
@@ -1937,7 +1937,7 @@ async def _delay_ready(self) -> None:
19371937
)
19381938
if len(current_bucket) >= max_concurrency:
19391939
try:
1940-
await utils.sane_wait_for(current_bucket, timeout=max_concurrency * 70.0)
1940+
await sane_wait_for(current_bucket, timeout=max_concurrency * 70.0)
19411941
except asyncio.TimeoutError:
19421942
fmt = "Shard ID %s failed to wait for chunks from a sub-bucket with length %d"
19431943
_log.warning(fmt, guild.shard_id, len(current_bucket))
@@ -1959,7 +1959,7 @@ async def _delay_ready(self) -> None:
19591959
# 110 reqs/minute w/ 1 req/guild plus some buffer
19601960
timeout = 61 * (len(children) / 110)
19611961
try:
1962-
await utils.sane_wait_for(futures, timeout=timeout)
1962+
await sane_wait_for(futures, timeout=timeout)
19631963
except asyncio.TimeoutError:
19641964
_log.warning(
19651965
("Shard ID %s failed to wait for chunks (timeout=%.2f) for %d guilds"),

discord/utils/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from __future__ import annotations
2727

2828
import array
29-
import asyncio
3029
import collections.abc
3130
import datetime
3231
import json
@@ -303,16 +302,6 @@ def _to_json(obj: Any) -> str:
303302
_from_json = json.loads
304303

305304

306-
async def sane_wait_for(futures, *, timeout):
307-
ensured = [asyncio.ensure_future(fut) for fut in futures]
308-
done, pending = await asyncio.wait(ensured, timeout=timeout, return_when=asyncio.ALL_COMPLETED)
309-
310-
if len(pending) != 0:
311-
raise asyncio.TimeoutError()
312-
313-
return done
314-
315-
316305
def get_slots(cls: type[Any]) -> Iterator[str]:
317306
for mro in reversed(cls.__mro__):
318307
try:

discord/utils/private.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,13 @@ async def maybe_awaitable(f: Callable[P, T | Awaitable[T]], *args: P.args, **kwa
401401
reveal_type(f)
402402
return await value
403403
return value
404+
405+
406+
async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: float) -> set[asyncio.Future[T]]:
407+
ensured = [asyncio.ensure_future(fut) for fut in futures]
408+
done, pending = await asyncio.wait(ensured, timeout=timeout, return_when=asyncio.ALL_COMPLETED)
409+
410+
if len(pending) != 0:
411+
raise asyncio.TimeoutError()
412+
413+
return done

discord/voice_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from .player import AudioPlayer, AudioSource
5757
from .sinks import RawData, RecordingException, Sink
5858
from .utils import MISSING
59+
from .utils.private import sane_wait_for
5960

6061
if TYPE_CHECKING:
6162
from . import abc
@@ -392,7 +393,7 @@ async def connect(self, *, reconnect: bool, timeout: float) -> None:
392393
await self.voice_connect()
393394

394395
try:
395-
await utils.sane_wait_for(futures, timeout=timeout)
396+
await sane_wait_for(futures, timeout=timeout)
396397
except asyncio.TimeoutError:
397398
await self.disconnect(force=True)
398399
raise

0 commit comments

Comments
 (0)