summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-10-21 17:46:59 +0300
committerMaxim Devaev <[email protected]>2024-10-21 17:46:59 +0300
commitcda32a083faf3e7326cfe317336e473c905c6dfd (patch)
tree19445e4098d4603f3b2cd296504a648110712af1 /kvmd/aiotools.py
parentb67a2325842a6f407d3935f8445d50cb8bf307f2 (diff)
new events model
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r--kvmd/aiotools.py19
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
# =====