Merge pull request #1071 from r0fls/1062-docs
udpate docs with add_task app injection
This commit is contained in:
commit
c14e99cef0
|
@ -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))
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue
Block a user