mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
refactoring
This commit is contained in:
@@ -105,6 +105,30 @@ class AioNotifier:
|
||||
await self.__queue.get()
|
||||
|
||||
|
||||
# =====
|
||||
class AioStage:
|
||||
def __init__(self) -> None:
|
||||
self.__fut = asyncio.Future() # type: ignore
|
||||
|
||||
def set_passed(self, multi: bool=False) -> None:
|
||||
if multi and self.__fut.done():
|
||||
return
|
||||
self.__fut.set_result(None)
|
||||
|
||||
def is_passed(self) -> bool:
|
||||
return self.__fut.done()
|
||||
|
||||
async def wait_passed(self, timeout: float=-1) -> bool:
|
||||
if timeout >= 0:
|
||||
try:
|
||||
await asyncio.wait_for(self.__fut, timeout=timeout)
|
||||
except asyncio.TimeoutError:
|
||||
return False
|
||||
else:
|
||||
await self.__fut
|
||||
return True
|
||||
|
||||
|
||||
# =====
|
||||
class AioExclusiveRegion:
|
||||
def __init__(
|
||||
|
||||
Reference in New Issue
Block a user