Use create_task instead ensure_future

This commit is contained in:
Lonami Exo 2018-06-14 23:33:56 +02:00
parent f95400ea7e
commit 091b03c635
2 changed files with 7 additions and 10 deletions

View File

@ -150,13 +150,12 @@ class UpdateMethods(UserMethods):
itertools.chain(update.users, update.chats)}
for u in update.updates:
u._entities = entities
asyncio.ensure_future(
self._dispatch_update(u), loop=self._loop)
self._loop.create_task(self._dispatch_update(u))
return
if isinstance(update, types.UpdateShort):
update = update.update
update._entities = {}
asyncio.ensure_future(self._dispatch_update(update), loop=self._loop)
self._loop.create_task(self._dispatch_update(update))
async def _dispatch_update(self, update):
if self._events_pending_resolve:

View File

@ -232,12 +232,10 @@ class MTProtoSender:
raise _last_error
__log__.debug('Starting send loop')
self._send_loop_handle = asyncio.ensure_future(
self._send_loop(), loop=self._loop)
self._send_loop_handle = self._loop.create_task(self._send_loop())
__log__.debug('Starting receive loop')
self._recv_loop_handle = asyncio.ensure_future(
self._recv_loop(), loop=self._loop)
self._recv_loop_handle = self._loop.create_task(self._recv_loop())
if self._is_first_query:
__log__.debug('Running first query')
@ -352,11 +350,11 @@ class MTProtoSender:
continue
except ConnectionError as e:
__log__.info('Connection reset while receiving %s', e)
asyncio.ensure_future(self._reconnect(), loop=self._loop)
self._loop.create_task(self._reconnect())
break
except OSError as e:
__log__.warning('OSError while receiving %s', e)
asyncio.ensure_future(self._reconnect(), loop=self._loop)
self._loop.create_task(self._reconnect())
break
# TODO Check salt, session_id and sequence_number
@ -375,7 +373,7 @@ class MTProtoSender:
# an actually broken authkey?
__log__.warning('Broken authorization key?: {}'.format(e))
self.state.auth_key = None
asyncio.ensure_future(self._reconnect(), loop=self._loop)
self._loop.create_task(self._reconnect())
break
except SecurityError as e:
# A step while decoding had the incorrect data. This message