Skip to content

Commit 0dacf40

Browse files
committed
v3 tutorial: document current_task() method.
1 parent 690d0fc commit 0dacf40

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

v3/docs/TUTORIAL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,20 @@ async def bar():
15481548
print('Task is now cancelled')
15491549
asyncio.run(bar())
15501550
```
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+
```
15511565

15521566
###### [Contents](./TUTORIAL.md#contents)
15531567

0 commit comments

Comments
 (0)