diff options
author | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
commit | cda32a083faf3e7326cfe317336e473c905c6dfd (patch) | |
tree | 19445e4098d4603f3b2cd296504a648110712af1 /kvmd/aiotools.py | |
parent | b67a2325842a6f407d3935f8445d50cb8bf307f2 (diff) |
new events model
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r-- | kvmd/aiotools.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py index 5d284a94..b1747f16 100644 --- a/kvmd/aiotools.py +++ b/kvmd/aiotools.py @@ -232,25 +232,26 @@ async def close_writer(writer: asyncio.StreamWriter) -> bool: # ===== class AioNotifier: def __init__(self) -> None: - self.__queue: "asyncio.Queue[None]" = asyncio.Queue() + self.__queue: "asyncio.Queue[int]" = asyncio.Queue() - def notify(self) -> None: - self.__queue.put_nowait(None) + def notify(self, mask: int=0) -> None: + self.__queue.put_nowait(mask) - async def wait(self, timeout: (float | None)=None) -> None: + async def wait(self, timeout: (float | None)=None) -> int: + mask = 0 if timeout is None: - await self.__queue.get() + mask = await self.__queue.get() else: try: - await asyncio.wait_for( + mask = await asyncio.wait_for( asyncio.ensure_future(self.__queue.get()), timeout=timeout, ) except asyncio.TimeoutError: - return # False + return -1 while not self.__queue.empty(): - await self.__queue.get() - # return True + mask |= await self.__queue.get() + return mask # ===== |