summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-03-02 01:26:43 +0300
committerDevaev Maxim <[email protected]>2020-03-02 01:26:43 +0300
commit8972357dbc2147c1a02fd3470befd2b4aed9fc05 (patch)
tree63dfcdf09da43327bd48ba641a399d6ded3bb71d /kvmd/aiotools.py
parente855976f05775359b774c3d5d6c3a6f6532efce6 (diff)
changed region methods to async
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r--kvmd/aiotools.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py
index 9f854489..f8965edd 100644
--- a/kvmd/aiotools.py
+++ b/kvmd/aiotools.py
@@ -32,7 +32,6 @@ import typing
from typing import List
from typing import Callable
from typing import Coroutine
-from typing import Generator
from typing import AsyncGenerator
from typing import Type
from typing import TypeVar
@@ -136,34 +135,34 @@ class AioExclusiveRegion:
def is_busy(self) -> bool:
return self.__busy
- def enter(self) -> None:
+ async def enter(self) -> None:
if not self.__busy:
self.__busy = True
return
raise self.__exc_type()
- def exit(self) -> None:
+ async def exit(self) -> None:
self.__busy = False
- @contextlib.contextmanager
- def exit_only_on_exception(self) -> Generator[None, None, None]:
- self.enter()
+ @contextlib.asynccontextmanager
+ async def exit_only_on_exception(self) -> AsyncGenerator[None, None]:
+ await self.enter()
try:
yield
except: # noqa: E722
- self.exit()
+ await self.exit()
raise
- def __enter__(self) -> None:
- self.enter()
+ async def __aenter__(self) -> None:
+ await self.enter()
- def __exit__(
+ async def __aexit__(
self,
_exc_type: Type[BaseException],
_exc: BaseException,
_tb: types.TracebackType,
) -> None:
- self.exit()
+ await self.exit()
# =====