Skip to content

Commit

Permalink
Avoid multiple async call in HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Dec 23, 2024
1 parent 629056f commit b8fefda
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions twitchio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ async def close(self) -> None:
logger.debug("%s session closed successfully.", self.__class__.__qualname__)

async def request(self, route: Route) -> RawResponse | str | None:
await self._init_session()
if not self._session_set:
await self._init_session()

assert self._session is not None

logger.debug("Attempting a request to %r with %s.", route, self.__class__.__qualname__)
Expand Down Expand Up @@ -466,7 +468,9 @@ async def request_json(self, route: Route) -> Any:
return data

async def _request_asset_head(self, url: str) -> dict[str, str]:
await self._init_session()
if not self._session_set:
await self._init_session()

assert self._session is not None

logger.debug('Attempting to request headers for asset "%s" with %s.', url, self.__class__.__qualname__)
Expand All @@ -479,7 +483,9 @@ async def _request_asset_head(self, url: str) -> dict[str, str]:
return dict(resp.headers)

async def _request_asset(self, asset: Asset, *, chunk_size: int = 1024) -> AsyncIterator[bytes]:
await self._init_session()
if not self._session_set:
await self._init_session()

assert self._session is not None

logger.debug('Attempting a request to asset "%r" with %s.', asset, self.__class__.__qualname__)
Expand Down

0 comments on commit b8fefda

Please sign in to comment.