mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Implement a mechanism to notify of connection failures (#852)
This commit is contained in:
@@ -218,6 +218,14 @@ class TelegramBaseClient(abc.ABC):
|
||||
def loop(self):
|
||||
return self._loop
|
||||
|
||||
@property
|
||||
def disconnected(self):
|
||||
"""
|
||||
Future that resolves when the connection to Telegram
|
||||
ends, either by user action or in the background.
|
||||
"""
|
||||
return self._sender.disconnected
|
||||
|
||||
# endregion
|
||||
|
||||
# region Connecting
|
||||
|
@@ -14,6 +14,19 @@ class UpdateMethods(UserMethods):
|
||||
|
||||
# region Public methods
|
||||
|
||||
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
|
||||
the latter case, said error will ``raise`` so you have a chance
|
||||
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.disconnected`` in
|
||||
this situation instead.
|
||||
"""
|
||||
self.loop.run_until_complete(self.disconnected)
|
||||
|
||||
def on(self, event):
|
||||
"""
|
||||
Decorator helper method around add_event_handler().
|
||||
|
Reference in New Issue
Block a user