Skip to content

Commit

Permalink
Refactor the condflag class
Browse files Browse the repository at this point in the history
  • Loading branch information
exflikt committed Nov 29, 2024
1 parent 8a606e7 commit f473b8c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/store/placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class ModifiedFlag(Flag):


class ModifiedCondFlag:
_condvar: asyncio.Condition = asyncio.Condition()
flag: ModifiedFlag = ModifiedFlag.ORIGINAL
_condvar: asyncio.Condition
_flag: ModifiedFlag

def __init__(self):
self._condvar = asyncio.Condition()
self._flag = ModifiedFlag.ORIGINAL

async def __aenter__(self):
await self._condvar.__aenter__()
Expand All @@ -49,15 +53,14 @@ async def __aexit__(self, exc_type, exc, tb) -> None:

async def wait(self) -> ModifiedFlag:
await self._condvar.wait()
flag = self.flag
flag = self._flag
if len(self._condvar._waiters) == 0:
self.flag = ModifiedFlag.ORIGINAL
self._flag = ModifiedFlag.ORIGINAL
return flag

def notify_all(self, flag: ModifiedFlag | None = None):
def notify_all(self, flag: ModifiedFlag):
self._flag |= flag
self._condvar.notify_all()
if flag is not None:
self.flag |= flag


class Table:
Expand Down

0 comments on commit f473b8c

Please sign in to comment.