aboutsummaryrefslogtreecommitdiff
path: root/discord/ui
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-27 23:31:48 -0400
committerRapptz <[email protected]>2021-05-27 23:31:48 -0400
commit65db814d4a48754be6be2dc5d013e0e44a0cac49 (patch)
tree78b3557e2a2f225d062700195b2c6337319577fe /discord/ui
parentFix extraneous colons in the documentation for ButtonStyle (diff)
downloaddiscord.py-65db814d4a48754be6be2dc5d013e0e44a0cac49.tar.xz
discord.py-65db814d4a48754be6be2dc5d013e0e44a0cac49.zip
Add a way to wait for a view to finish its interactions
Diffstat (limited to 'discord/ui')
-rw-r--r--discord/ui/view.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/discord/ui/view.py b/discord/ui/view.py
index 57faa312..547d8280 100644
--- a/discord/ui/view.py
+++ b/discord/ui/view.py
@@ -118,6 +118,7 @@ class View:
self.id = os.urandom(16).hex()
self._cancel_callback: Optional[Callable[[View], None]] = None
+ self._stopped = asyncio.Event()
def to_components(self) -> List[Dict[str, Any]]:
def key(item: Item) -> int:
@@ -212,9 +213,17 @@ class View:
This operation cannot be undone.
"""
+ self._stopped.set()
if self._cancel_callback:
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:
def __init__(self, state):