mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 07:24:51 +00:00
Make run() accept a coroutine
This commit is contained in:
parent
06cb2a1168
commit
5834e38f14
1 changed files with 14 additions and 8 deletions
|
|
@ -288,19 +288,25 @@ class Client(Methods, BaseClient):
|
||||||
|
|
||||||
await self.stop()
|
await self.stop()
|
||||||
|
|
||||||
def run(self):
|
def run(self, coroutine=None):
|
||||||
"""Use this method to automatically start and idle a Client.
|
"""Use this method to automatically start and idle a Client.
|
||||||
Requires no parameters.
|
If a coroutine is passed as argument this method will start the client, run the coroutine
|
||||||
|
until is complete and then stop the client automatically.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
coroutine: (``Coroutine``, *optional*):
|
||||||
|
Pass a coroutine to run it until is complete.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>`
|
:class:`Error <pyrogram.Error>`
|
||||||
"""
|
"""
|
||||||
asyncio.get_event_loop().run_until_complete(
|
run = asyncio.get_event_loop().run_until_complete
|
||||||
asyncio.gather(
|
|
||||||
self.start(),
|
run(self.start())
|
||||||
self.idle()
|
run(coroutine or self.idle())
|
||||||
)
|
|
||||||
)
|
if coroutine:
|
||||||
|
run(self.stop())
|
||||||
|
|
||||||
def add_handler(self, handler, group: int = 0):
|
def add_handler(self, handler, group: int = 0):
|
||||||
"""Use this method to register an update handler.
|
"""Use this method to register an update handler.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue