feat: now AsyncVikingClient and VikingClient can be used in "async with" and "with"

This commit is contained in:
2025-08-14 09:34:38 +03:00
parent e673c1fbb5
commit 9ada61b63c
2 changed files with 32 additions and 2 deletions
+13 -1
View File
@@ -14,8 +14,20 @@ class VikingClient(AsyncVikingClient):
session = ClientSession(loop=self._loop)
super().__init__(user_hash, api_timeout, session)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def close(self):
if not self._session.closed:
self._loop.run_until_complete(self._session.close())
self._loop.close()
def _cleanup(self):
self._loop.run_until_complete(self._session.close())
if not self._session.closed:
self._loop.run_until_complete(self._session.close())
self._loop.close()
def get_max_pages(self, path: str = "") -> int: