Also use loop.create_task() with asyncio
This commit is contained in:
parent
f2dcc50515
commit
5ed6b443db
|
@ -24,28 +24,29 @@ except ImportError:
|
||||||
if asyncio is None:
|
if asyncio is None:
|
||||||
asyncio = trollius
|
asyncio = trollius
|
||||||
|
|
||||||
|
def _create_task(coro):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
if hasattr(loop, 'create_task'):
|
||||||
|
return loop.create_task(coro)
|
||||||
|
else:
|
||||||
|
return GreenTask(coro, loop=loop)
|
||||||
|
|
||||||
|
|
||||||
if trollius is not None:
|
if trollius is not None:
|
||||||
def _async(future):
|
def _async(future):
|
||||||
# trollius iscoroutine() accepts trollius and asyncio coroutine
|
# trollius iscoroutine() accepts trollius and asyncio coroutine
|
||||||
# objects
|
# objects
|
||||||
if trollius.iscoroutine(future):
|
if trollius.iscoroutine(future):
|
||||||
loop = asyncio.get_event_loop()
|
return _create_task(future)
|
||||||
return loop.create_task(future)
|
|
||||||
else:
|
else:
|
||||||
return future
|
return future
|
||||||
|
|
||||||
def _create_task(coro):
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
return loop.create_task(coro)
|
|
||||||
else:
|
else:
|
||||||
def _async(future):
|
def _async(future):
|
||||||
if asyncio.iscoroutine(future):
|
if asyncio.iscoroutine(future):
|
||||||
return GreenTask(future)
|
return _create_task(future)
|
||||||
else:
|
else:
|
||||||
return future
|
return future
|
||||||
|
|
||||||
def _create_task(coro):
|
|
||||||
return GreenTask(coro)
|
|
||||||
|
|
||||||
_FUTURE_CLASSES = (asyncio.Future,)
|
_FUTURE_CLASSES = (asyncio.Future,)
|
||||||
if trollius is not None and trollius is not asyncio:
|
if trollius is not None and trollius is not asyncio:
|
||||||
|
|
Loading…
Reference in New Issue