Merge pull request #1071 from r0fls/1062-docs

udpate docs with add_task app injection
This commit is contained in:
Raphael Deem 2017-12-28 02:01:23 -08:00 committed by GitHub
commit c14e99cef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -110,3 +110,23 @@ async def notify_server_started_after_five_seconds():
app.add_task(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))
`