Implement a mechanism to notify of connection failures (#852)

This commit is contained in:
Dan Elkouby
2018-06-17 20:29:41 +03:00
committed by Lonami
parent d9d586171f
commit d5b349e031
3 changed files with 44 additions and 3 deletions

View File

@@ -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

View File

@@ -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().