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)} itertools.chain(update.users, update.chats)}
for u in update.updates: for u in update.updates:
u._entities = entities u._entities = entities
asyncio.ensure_future( self._loop.create_task(self._dispatch_update(u))
self._dispatch_update(u), loop=self._loop)
return return
if isinstance(update, types.UpdateShort): if isinstance(update, types.UpdateShort):
update = update.update update = update.update
update._entities = {} 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): async def _dispatch_update(self, update):
if self._events_pending_resolve: if self._events_pending_resolve:

View File

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