From b5e46e83e27ccfd63e864522fdff9054d6f76c9a Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Sun, 12 Feb 2017 12:07:59 -0800 Subject: [PATCH] ensure_future -> add_task --- sanic/sanic.py | 8 ++++---- tests/{test_ensure_future.py => test_create_task.py} | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename tests/{test_ensure_future.py => test_create_task.py} (96%) diff --git a/sanic/sanic.py b/sanic/sanic.py index 218937c5..fa2f298d 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -1,7 +1,7 @@ import logging import re import warnings -from asyncio import get_event_loop, ensure_future +from asyncio import get_event_loop from collections import deque from functools import partial from inspect import isawaitable, stack, getmodulename @@ -53,7 +53,7 @@ class Sanic: # Registration # -------------------------------------------------------------------- # - def ensure_future(self, task): + def add_task(self, task): """ Schedule a task to run later, after the loop has started. Different from asyncio.ensure_future in that it does not @@ -64,9 +64,9 @@ class Sanic: """ def run(app, loop): if callable(task): - ensure_future(task()) + loop.create_task(task()) else: - ensure_future(task) + loop.create_task(task) self.before_start.append(run) diff --git a/tests/test_ensure_future.py b/tests/test_create_task.py similarity index 96% rename from tests/test_ensure_future.py rename to tests/test_create_task.py index 385d8b88..76efff36 100644 --- a/tests/test_ensure_future.py +++ b/tests/test_create_task.py @@ -11,7 +11,7 @@ def test_ensure_future(): e.set() app = sanic.Sanic() - app.ensure_future(coro) + app.add_task(coro) @app.route('/early') def not_set(request):