Make run() accept coroutine functions

This commit is contained in:
Dan 2018-06-26 13:45:31 +02:00
parent 5e3618ccb7
commit 9dff15bd4f

View file

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