mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-17 03:51:05 +03:00
Allow run_until_disconnected when the loop is running
This commit is contained in:
parent
c1046c2acc
commit
db5cb74bdd
|
@ -16,6 +16,12 @@ class UpdateMethods(UserMethods):
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
async def _run_until_disconnected(self):
|
||||||
|
try:
|
||||||
|
await self.disconnected
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
await self.disconnect()
|
||||||
|
|
||||||
def run_until_disconnected(self):
|
def run_until_disconnected(self):
|
||||||
"""
|
"""
|
||||||
Runs the event loop until `disconnect` is called or if an error
|
Runs the event loop until `disconnect` is called or if an error
|
||||||
|
@ -23,14 +29,13 @@ class UpdateMethods(UserMethods):
|
||||||
the latter case, said error will ``raise`` so you have a chance
|
the latter case, said error will ``raise`` so you have a chance
|
||||||
to ``except`` it on your own code.
|
to ``except`` it on your own code.
|
||||||
|
|
||||||
This method shouldn't be called from ``async def`` as the loop
|
If the loop is already running, this method returns a coroutine
|
||||||
will be running already. Use ``await client.disconnected`` in
|
that you should await on your own code.
|
||||||
this situation instead.
|
|
||||||
"""
|
"""
|
||||||
try:
|
if self.loop.is_running():
|
||||||
self.loop.run_until_complete(self.disconnected)
|
return self._run_until_disconnected() # Let the user await it
|
||||||
except KeyboardInterrupt:
|
else:
|
||||||
self.loop.run_until_complete(self.disconnect())
|
self.loop.run_until_complete(self._run_until_disconnected())
|
||||||
|
|
||||||
def on(self, event):
|
def on(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user