diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index fb025819..866a756a 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -219,11 +219,12 @@ class TelegramBaseClient(abc.ABC): return self._loop @property - def connection_dropped(self): + def disconnected(self): """ - Future that resolves when the connection to Telegram ends. + Future that resolves when the connection to Telegram + ends, either by user action or in the background. """ - return self._sender.connection_dropped + return self._sender.disconnected # endregion diff --git a/telethon/client/updates.py b/telethon/client/updates.py index 1bd1bfc1..4685444e 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -14,7 +14,7 @@ class UpdateMethods(UserMethods): # region Public methods - def run_loop(self): + def run_until_disconnected(self): """ Runs the event loop until `disconnect` is called or if an error while connecting/sending/receiving occurs in the background. In @@ -22,10 +22,10 @@ class UpdateMethods(UserMethods): to ``except`` it on your own code. This method shouldn't be called from ``async def`` as the loop - will be running already. Use ``await client.connection_dropped`` - in this situation instead. + will be running already. Use ``await client.disconnected`` in + this situation instead. """ - self.loop.run_until_complete(self.connection_dropped) + self.loop.run_until_complete(self.disconnected) def on(self, event): """ diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 6a4970f3..f27ee5ef 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -63,7 +63,7 @@ class MTProtoSender: # pending futures should be cancelled. self._user_connected = False self._reconnecting = False - self._connection_dropped = None + self._disconnected = None # We need to join the loops upon disconnection self._send_loop_handle = None @@ -159,9 +159,9 @@ class MTProtoSender: __log__.info('Disconnection from {} complete!'.format(self._ip)) if error: - self._connection_dropped.set_exception(error) + self._disconnected.set_exception(error) else: - self._connection_dropped.set_result(None) + self._disconnected.set_result(None) def send(self, request, ordered=False): """ @@ -205,14 +205,15 @@ class MTProtoSender: return message.future @property - def connection_dropped(self): + def disconnected(self): """ - Future that resolves when the connection to Telegram ends. + Future that resolves when the connection to Telegram + ends, either by user action or in the background. """ - if self._connection_dropped is not None: - return self._connection_dropped + if self._disconnected is not None: + return self._disconnected else: - raise ConnectionError('No connection yet') + raise ConnectionError('Sender was never connected') # Private methods @@ -262,8 +263,8 @@ class MTProtoSender: self._recv_loop_handle = self._loop.create_task(self._recv_loop()) # First connection or manual reconnection after a failure - if self._connection_dropped is None or self._connection_dropped.done(): - self._connection_dropped = asyncio.Future() + if self._disconnected is None or self._disconnected.done(): + self._disconnected = asyncio.Future() __log__.info('Connection to {} complete!'.format(self._ip)) async def _reconnect(self):