mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-06 15:14:52 +00:00
Make run() accept coroutine functions
This commit is contained in:
parent
5e3618ccb7
commit
9dff15bd4f
1 changed files with 10 additions and 2 deletions
|
|
@ -20,6 +20,7 @@ import asyncio
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import getpass
|
import getpass
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
|
@ -328,11 +329,18 @@ class Client(Methods, BaseClient):
|
||||||
run = asyncio.get_event_loop().run_until_complete
|
run = asyncio.get_event_loop().run_until_complete
|
||||||
|
|
||||||
run(self.start())
|
run(self.start())
|
||||||
run(coroutine or self.idle())
|
|
||||||
|
|
||||||
if coroutine:
|
run(
|
||||||
|
coroutine if inspect.iscoroutine(coroutine)
|
||||||
|
else coroutine() if coroutine
|
||||||
|
else self.idle()
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.is_started:
|
||||||
run(self.stop())
|
run(self.stop())
|
||||||
|
|
||||||
|
return coroutine
|
||||||
|
|
||||||
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