simplified AioNotifier()

This commit is contained in:
Maxim Devaev
2022-08-07 19:04:32 +03:00
parent aa630988cc
commit ec9785b4be
18 changed files with 43 additions and 54 deletions

View File

@@ -232,10 +232,7 @@ class AioNotifier:
def __init__(self) -> None:
self.__queue: "asyncio.Queue[None]" = asyncio.Queue()
async def notify(self) -> None:
await self.__queue.put(None)
def notify_sync(self) -> None:
def notify(self) -> None:
self.__queue.put_nowait(None)
async def wait(self, timeout: Optional[float]=None) -> None:
@@ -299,7 +296,7 @@ class AioExclusiveRegion:
self.__busy = True
try:
if self.__notifier:
await self.__notifier.notify()
self.__notifier.notify()
except: # noqa: E722
self.__busy = False
raise
@@ -309,7 +306,7 @@ class AioExclusiveRegion:
async def exit(self) -> None:
self.__busy = False
if self.__notifier:
await self.__notifier.notify()
self.__notifier.notify()
async def __aenter__(self) -> None:
await self.enter()