99# noinspection PyProtectedMember
1010from lxml .etree import _Element
1111
12+ from .task import SingleFlight
1213from .utils import xml_to_dict
1314
1415# noinspection HttpUrlsUsage
@@ -32,6 +33,7 @@ class AndroidRepository:
3233 def __init__ (self , client : aiohttp .ClientSession ):
3334 self ._client = client
3435 self ._tree : _Element | None = None
36+ self ._task_manager : SingleFlight = SingleFlight ()
3537
3638 @staticmethod
3739 def cached_instance (client : aiohttp .ClientSession ) -> 'AndroidRepository' :
@@ -120,7 +122,7 @@ def get_best_archive_url(pkg_dict: dict) -> str:
120122 else :
121123 raise ValueError (f"Unknown archives format: { archives } " )
122124
123- async def download_archive (self , archive_name : str , output_dir : str | None = None ) -> str :
125+ async def _download_archive_task (self , archive_name : str , output_dir : str | None ) -> str :
124126 if output_dir is None :
125127 output_dir = "."
126128 if not os .path .isdir (output_dir ):
@@ -138,6 +140,14 @@ async def download_archive(self, archive_name: str, output_dir: str | None = Non
138140 raise ValueError (f"Missing download tmp: { tmp_file_path } " )
139141 return target_file_path
140142
143+ async def download_archive (self , archive_name : str , output_dir : str | None = None ) -> str :
144+ return await self ._task_manager .run (
145+ archive_name ,
146+ self ._download_archive_task ,
147+ archive_name ,
148+ output_dir
149+ )
150+
141151 async def get_packages (self , path : str , channel : str | None = None ) -> list [dict ]:
142152 pkg_elements = await self ._get_package_elements (path )
143153 return sorted ([
0 commit comments