mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 05:19:41 +00:00
Make is_connected a property
This is consistent with the rest of is_ properties
This commit is contained in:
@@ -308,12 +308,29 @@ async def connect(self: 'TelegramClient') -> None:
|
||||
|
||||
self._updates_handle = asyncio.create_task(self._update_loop())
|
||||
|
||||
|
||||
def is_connected(self: 'TelegramClient') -> bool:
|
||||
sender = getattr(self, '_sender', None)
|
||||
return sender and sender.is_connected()
|
||||
return self._sender.is_connected()
|
||||
|
||||
|
||||
async def disconnect(self: 'TelegramClient'):
|
||||
return await _disconnect_coro(self)
|
||||
await _disconnect(self)
|
||||
|
||||
# Also clean-up all exported senders because we're done with them
|
||||
async with self._borrow_sender_lock:
|
||||
for state, sender in self._borrowed_senders.values():
|
||||
# Note that we're not checking for `state.should_disconnect()`.
|
||||
# If the user wants to disconnect the client, ALL connections
|
||||
# to Telegram (including exported senders) should be closed.
|
||||
#
|
||||
# Disconnect should never raise, so there's no try/except.
|
||||
await sender.disconnect()
|
||||
# Can't use `mark_disconnected` because it may be borrowed.
|
||||
state._connected = False
|
||||
|
||||
# If any was borrowed
|
||||
self._borrowed_senders.clear()
|
||||
|
||||
|
||||
def set_proxy(self: 'TelegramClient', proxy: typing.Union[tuple, dict]):
|
||||
init_proxy = None
|
||||
@@ -333,24 +350,6 @@ def set_proxy(self: 'TelegramClient', proxy: typing.Union[tuple, dict]):
|
||||
else:
|
||||
connection._proxy = proxy
|
||||
|
||||
async def _disconnect_coro(self: 'TelegramClient'):
|
||||
await _disconnect(self)
|
||||
|
||||
# Also clean-up all exported senders because we're done with them
|
||||
async with self._borrow_sender_lock:
|
||||
for state, sender in self._borrowed_senders.values():
|
||||
# Note that we're not checking for `state.should_disconnect()`.
|
||||
# If the user wants to disconnect the client, ALL connections
|
||||
# to Telegram (including exported senders) should be closed.
|
||||
#
|
||||
# Disconnect should never raise, so there's no try/except.
|
||||
await sender.disconnect()
|
||||
# Can't use `mark_disconnected` because it may be borrowed.
|
||||
state._connected = False
|
||||
|
||||
# If any was borrowed
|
||||
self._borrowed_senders.clear()
|
||||
|
||||
|
||||
async def _disconnect(self: 'TelegramClient'):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user