ensure_future -> add_task
This commit is contained in:
parent
94b2352c2c
commit
b5e46e83e2
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
from asyncio import get_event_loop, ensure_future
|
from asyncio import get_event_loop
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import isawaitable, stack, getmodulename
|
from inspect import isawaitable, stack, getmodulename
|
||||||
|
@ -53,7 +53,7 @@ class Sanic:
|
||||||
# Registration
|
# Registration
|
||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
|
|
||||||
def ensure_future(self, task):
|
def add_task(self, task):
|
||||||
"""
|
"""
|
||||||
Schedule a task to run later, after the loop has started.
|
Schedule a task to run later, after the loop has started.
|
||||||
Different from asyncio.ensure_future in that it does not
|
Different from asyncio.ensure_future in that it does not
|
||||||
|
@ -64,9 +64,9 @@ class Sanic:
|
||||||
"""
|
"""
|
||||||
def run(app, loop):
|
def run(app, loop):
|
||||||
if callable(task):
|
if callable(task):
|
||||||
ensure_future(task())
|
loop.create_task(task())
|
||||||
else:
|
else:
|
||||||
ensure_future(task)
|
loop.create_task(task)
|
||||||
|
|
||||||
self.before_start.append(run)
|
self.before_start.append(run)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ def test_ensure_future():
|
||||||
e.set()
|
e.set()
|
||||||
|
|
||||||
app = sanic.Sanic()
|
app = sanic.Sanic()
|
||||||
app.ensure_future(coro)
|
app.add_task(coro)
|
||||||
|
|
||||||
@app.route('/early')
|
@app.route('/early')
|
||||||
def not_set(request):
|
def not_set(request):
|
Loading…
Reference in New Issue
Block a user