Add a way to wait for a view to finish its interactions
This commit is contained in:
parent
77ed476129
commit
65db814d4a
@ -118,6 +118,7 @@ class View:
|
|||||||
|
|
||||||
self.id = os.urandom(16).hex()
|
self.id = os.urandom(16).hex()
|
||||||
self._cancel_callback: Optional[Callable[[View], None]] = None
|
self._cancel_callback: Optional[Callable[[View], None]] = None
|
||||||
|
self._stopped = asyncio.Event()
|
||||||
|
|
||||||
def to_components(self) -> List[Dict[str, Any]]:
|
def to_components(self) -> List[Dict[str, Any]]:
|
||||||
def key(item: Item) -> int:
|
def key(item: Item) -> int:
|
||||||
@ -212,9 +213,17 @@ class View:
|
|||||||
|
|
||||||
This operation cannot be undone.
|
This operation cannot be undone.
|
||||||
"""
|
"""
|
||||||
|
self._stopped.set()
|
||||||
if self._cancel_callback:
|
if self._cancel_callback:
|
||||||
self._cancel_callback(self)
|
self._cancel_callback(self)
|
||||||
|
|
||||||
|
async def wait(self) -> None:
|
||||||
|
"""Waits until the view has finished interacting.
|
||||||
|
|
||||||
|
A view is considered finished when :meth:`stop` is called.
|
||||||
|
"""
|
||||||
|
await self._stopped.wait()
|
||||||
|
|
||||||
|
|
||||||
class ViewStore:
|
class ViewStore:
|
||||||
def __init__(self, state):
|
def __init__(self, state):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user