udpate docs with add_task app injection

This commit is contained in:
Raphael Deem 2017-12-28 01:59:16 -08:00
parent 2f0076f429
commit c91a806774

View File

@ -110,3 +110,23 @@ async def notify_server_started_after_five_seconds():
app.add_task(notify_server_started_after_five_seconds())
```
Sanic will attempt to automatically inject the app, passing it as an argument to the task:
```python
async def notify_server_started_after_five_seconds(app):
await asyncio.sleep(5)
print(app.name)
app.add_task(notify_server_started_after_five_seconds)
```
Or you can pass the app explicitly for the same effect:
```python
async def notify_server_started_after_five_seconds(app):
await asyncio.sleep(5)
print(app.name)
app.add_task(notify_server_started_after_five_seconds(app))
`