Create a separate method to start reconnections

This commit is contained in:
Lonami Exo 2018-06-24 10:44:31 +02:00
parent 0d0e78e10b
commit 184424957d

View File

@ -305,6 +305,11 @@ class MTProtoSender:
__log__.error('Failed to reconnect automatically.')
await self._disconnect(error=ConnectionError())
def _start_reconnect(self):
"""Starts a reconnection in the background."""
if self._user_connected:
self._loop.create_task(self._reconnect())
def _clean_containers(self, msg_ids):
"""
Helper method to clean containers from the pending messages
@ -378,7 +383,7 @@ class MTProtoSender:
__log__.exception('Unhandled exception while receiving')
await asyncio.sleep(1)
self._loop.create_task(self._reconnect())
self._start_reconnect()
break
else:
# Remove the cancelled messages from pending
@ -417,7 +422,7 @@ class MTProtoSender:
__log__.exception('Unhandled exception while receiving')
await asyncio.sleep(1)
self._loop.create_task(self._reconnect())
self._start_reconnect()
break
# TODO Check salt, session_id and sequence_number
@ -436,7 +441,7 @@ class MTProtoSender:
# an actually broken authkey?
__log__.warning('Broken authorization key?: {}'.format(e))
self.state.auth_key = None
self._loop.create_task(self._reconnect())
self._start_reconnect()
break
except SecurityError as e:
# A step while decoding had the incorrect data. This message