We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 690d0fc commit 0dacf40Copy full SHA for 0dacf40
v3/docs/TUTORIAL.md
@@ -1548,6 +1548,20 @@ async def bar():
1548
print('Task is now cancelled')
1549
asyncio.run(bar())
1550
```
1551
+As of [PR6883](https://github.com/micropython/micropython/pull/6883) the
1552
+`current_task()` method is supported. This enables a task to pass itself to
1553
+other tasks, enabling them to cancel it. It also facilitates the following
1554
+pattern:
1555
+
1556
+```python
1557
+class Foo:
1558
+ async def run(self):
1559
+ self.task = asyncio.current_task()
1560
+ # code omitted
1561
1562
+ def cancel(self):
1563
+ self.task.cancel()
1564
+```
1565
1566
###### [Contents](./TUTORIAL.md#contents)
1567
0 commit comments