Buckets:
| """HACS Decorators.""" | |
| from __future__ import annotations | |
| import asyncio | |
| from collections.abc import Coroutine | |
| from functools import wraps | |
| from typing import TYPE_CHECKING, Any | |
| from ..const import DEFAULT_CONCURRENT_BACKOFF_TIME, DEFAULT_CONCURRENT_TASKS | |
| if TYPE_CHECKING: | |
| from ..base import HacsBase | |
| def concurrent( | |
| concurrenttasks: int = DEFAULT_CONCURRENT_TASKS, | |
| backoff_time: int = DEFAULT_CONCURRENT_BACKOFF_TIME, | |
| ) -> Coroutine[Any, Any, None]: | |
| """Return a modified function.""" | |
| max_concurrent = asyncio.Semaphore(concurrenttasks) | |
| def inner_function(function) -> Coroutine[Any, Any, None]: | |
| async def wrapper(*args, **kwargs) -> None: | |
| hacs: HacsBase = getattr(args[0], "hacs", None) | |
| async with max_concurrent: | |
| result = await function(*args, **kwargs) | |
| if ( | |
| hacs is None | |
| or hacs.queue is None | |
| or hacs.queue.has_pending_tasks | |
| or "update" not in function.__name__ | |
| ): | |
| await asyncio.sleep(backoff_time) | |
| return result | |
| return wrapper | |
| return inner_function | |
Xet Storage Details
- Size:
- 1.22 kB
- Xet hash:
- 1250d9f01e0ad5a80a5ff08899607e36d94273cc8c18932920520a17e069f672
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.