summaryrefslogtreecommitdiffstats
path: root/Doc/library/asyncio-future.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/asyncio-future.rst')
-rw-r--r--Doc/library/asyncio-future.rst14
1 files changed, 10 insertions, 4 deletions
diff --git a/Doc/library/asyncio-future.rst b/Doc/library/asyncio-future.rst
index ff04339..19bf8a6 100644
--- a/Doc/library/asyncio-future.rst
+++ b/Doc/library/asyncio-future.rst
@@ -121,6 +121,16 @@ Future Object
or an exception set with :meth:`set_result` or
:meth:`set_exception` calls.
+ .. method:: cancelled()
+
+ Return ``True`` if the Future was *cancelled*.
+
+ The method is usually used to check if a Future is not
+ *cancelled* before setting a result or an exception for it::
+
+ if not fut.cancelled():
+ fut.set_result(42)
+
.. method:: add_done_callback(callback, *, context=None)
Add a callback to be run when the Future is *done*.
@@ -180,10 +190,6 @@ Future Object
.. versionadded:: 3.7
- .. method:: cancelled()
-
- Return ``True`` if the Future was *cancelled*.
-
This example creates a Future object, creates and schedules an
asynchronous Task to set result for the Future, and waits until